More work on pin_create
This commit is contained in:
80
src/io.s
80
src/io.s
@@ -1,6 +1,43 @@
|
|||||||
|
//---------Local variables ----------------------
|
||||||
|
.data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
typedef struct pin_s {
|
||||||
|
GPIO_TypeDef* GPIO;
|
||||||
|
uint16_t pinmask;
|
||||||
|
} pin_t;
|
||||||
|
*/
|
||||||
|
|
||||||
|
.set OFFSET_PIN_GPIO, 0
|
||||||
|
.set OFFSET_PIN_PINMASK, 8
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
static pin_t pin_t0;
|
||||||
|
static pin_t pin_t1;
|
||||||
|
static pin_t pin_t2;
|
||||||
|
static pin_t pin_t3;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
pin0: .space 8, 0 //storage for GPIO ptr
|
||||||
|
.hword 0 //storage for pinmask
|
||||||
|
pin1: .space 8, 0
|
||||||
|
.hword 0
|
||||||
|
pin2: .space 8, 0
|
||||||
|
.hword 0
|
||||||
|
pin3: .space 8, 0
|
||||||
|
.hword 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------Local Functions ------------------
|
//--------Local Functions ------------------
|
||||||
|
.text
|
||||||
|
|
||||||
|
|
||||||
//void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr)
|
//void pin_create(pin_t* pin, GPIO_TypeDef* GPIO, uint8_t pinnr)
|
||||||
|
|
||||||
//R0: address to pin struct, R1: address to GPIO, R2: pinnr (1 byte). No return value
|
//R0: address to pin struct, R1: address to GPIO, R2: pinnr (1 byte). No return value
|
||||||
@@ -10,33 +47,50 @@ pin_create:
|
|||||||
.set OFFSET_OTYPER, 0x4
|
.set OFFSET_OTYPER, 0x4
|
||||||
.set OFFSET_PUPDR, 0xC
|
.set OFFSET_PUPDR, 0xC
|
||||||
.set GPIO_MODE_IN, 0
|
.set GPIO_MODE_IN, 0
|
||||||
|
.set GPIO_PuPd_UP, 1
|
||||||
|
.set GPIO_OType_OD, 1
|
||||||
|
|
||||||
MOV r5, #3 //r5 = 3
|
|
||||||
LSL r4, r2, #1 //r4 = pinnr*2
|
LSL r4, r2, #1 //r4 = pinnr*2
|
||||||
|
MOV r5, #3 //r5 = 3
|
||||||
LSL r5, r5, r4 //r5 = 3 << (pinnr*2)
|
LSL r5, r5, r4 //r5 = 3 << (pinnr*2)
|
||||||
|
|
||||||
//GPIO->MODER &=~ ( 3 << (pinnr*2)); //Clear the 2 bits (mode)
|
//GPIO->MODER &=~ ( 3 << (pinnr*2)); //Clear the 2 bits (mode)
|
||||||
LDR r3, [r1, #OFFSET_MODR] //r3 = GPIO->MODR
|
LDRB r3, [r1, #OFFSET_MODR] //r3 = GPIO->MODR
|
||||||
BIC r3, r3, r5 //r3 &= ~r5
|
BIC r3, r3, r5 //r3 &= ~r5
|
||||||
|
|
||||||
//GPIO->MODER |= GPIO_Mode_IN << (pinnr*2); //Set the correct bits for mode
|
//GPIO->MODER |= GPIO_Mode_IN << (pinnr*2); //Set the correct bits for mode
|
||||||
MOV r5, #GPIO_MODE_IN
|
MOV r6, #GPIO_MODE_IN
|
||||||
LSL r5, r5, r4 //r5 = GPIO_MODE_IN << (pinnr*2)
|
LSL r6, r6, r4 //r5 = GPIO_MODE_IN << (pinnr*2)
|
||||||
ORR r3, r3, r5 //r3 |= r5
|
ORR r3, r3, r6 //r3 |= r6
|
||||||
STR r3, [r1, #OFFSET_MODR] //GPIO->MODR = r3
|
STRB r3, [r1, #OFFSET_MODR] //GPIO->MODR = r3
|
||||||
|
|
||||||
//GPIO->OTYPER &=~ (1 << (pinnr*2)); //Clear the bit (otype)
|
//GPIO->PUPDR &=~ (3 <<(pinnr*2)); //clear the 2 bits (pp/od)
|
||||||
|
LDRB r3, [r1, #OFFSET_PUPDR] //r3 = GPIO->PUPDR
|
||||||
|
BIC r3, r3, r5 //r3 &= ~r5
|
||||||
|
|
||||||
|
//GPIO->PUPDR |= GPIO_PuPd_UP <<(pinnr*2); //set the correct bits for pp/od
|
||||||
|
MOV r6, #GPIO_PuPd_UP
|
||||||
|
LSL r6, r6, r4 //r6 = GPIO_PuPd_UP << (pinnr*2)
|
||||||
|
ORR r3, r3, r6 //r3 |= r6
|
||||||
|
STRB r3, [r1, #OFFSET_PUPDR] //GPIO->PUPDR = r3
|
||||||
|
|
||||||
|
//GPIO->OTYPER &=~ (1 << pinnr); //Clear the bit (otype)
|
||||||
|
LDRB r3, [r1, #OFFSET_OTYPER] //r3 = GPIO->OTYPER
|
||||||
|
MOV r5, #1 //r5 = 1
|
||||||
|
LSL r5, r5, r2 //r5 = 1 << pinnr
|
||||||
|
BIC r3, r3, r5 //r3 &= ~r5
|
||||||
|
|
||||||
//GPIO->OTYPER |= GPIO_OType_OD <<(pinnr*2); //set the correct bit for otype
|
//GPIO->OTYPER |= GPIO_OType_OD <<(pinnr*2); //set the correct bit for otype
|
||||||
/*
|
MOV r6, #GPIO_OType_OD
|
||||||
GPIO->PUPDR &=~ (3 <<(pinnr*2)); //clear the 2 bits (pp/od)
|
LSL r6, r6, r2 //r6 = GPIO_OType_OD << pinnr
|
||||||
GPIO->PUPDR |= GPIO_PuPd_UP <<(pinnr*2); //set the correct bits for pp/od
|
ORR r3, r3, r6 //r3 |= r6
|
||||||
|
STRB r3, [r1, #OFFSET_OTYPER] //GPIO->OTYPER = r3
|
||||||
|
|
||||||
pin->GPIO=GPIO; // Set the gpiopin in the pin structure
|
//pin->GPIO=GPIO; // Set the gpiopin in the pin structure
|
||||||
pin->pinmask=0x01<<pinnr; // Insert the pinmask
|
STR r1, [r0, #OFFSET_PIN_GPIO]
|
||||||
*/
|
|
||||||
|
|
||||||
|
//pin->pinmask=0x01<<pinnr; // Insert the pinmask
|
||||||
|
STR r5, [r0, #OFFSET_PIN_PINMASK]
|
||||||
|
|
||||||
|
|
||||||
//TODO: Implement
|
//TODO: Implement
|
||||||
|
|||||||
Reference in New Issue
Block a user