mirror of https://github.com/ARMmbed/mbed-os.git
Lots of small changes which get us compiling.
parent
b4c4ae8f09
commit
0b01040f47
|
|
@ -26,7 +26,7 @@ typedef struct {
|
||||||
PinName pin;
|
PinName pin;
|
||||||
int peripheral;
|
int peripheral;
|
||||||
int function;
|
int function;
|
||||||
#ifdef defined(TARGET_STM32F407)
|
#if defined(TARGET_STM32F407)
|
||||||
int alternate_function;
|
int alternate_function;
|
||||||
#endif
|
#endif
|
||||||
} PinMap;
|
} PinMap;
|
||||||
|
|
|
||||||
|
|
@ -62,9 +62,9 @@ typedef enum {
|
||||||
} SPIName;
|
} SPIName;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
I2C_0 = (int)I2C1_BASE,
|
I2C_1 = (int)I2C1_BASE,
|
||||||
I2C_1 = (int)I2C2_BASE,
|
I2C_2 = (int)I2C2_BASE,
|
||||||
I2C_2 = (int)I2C3_BASE
|
I2C_3 = (int)I2C3_BASE
|
||||||
} I2CName;
|
} I2CName;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
||||||
|
|
@ -20,28 +20,28 @@
|
||||||
#define DEVICE_PORTOUT 1
|
#define DEVICE_PORTOUT 1
|
||||||
#define DEVICE_PORTINOUT 1
|
#define DEVICE_PORTINOUT 1
|
||||||
|
|
||||||
#define DEVICE_INTERRUPTIN 1
|
#define DEVICE_INTERRUPTIN 0
|
||||||
|
|
||||||
#define DEVICE_ANALOGIN 1
|
#define DEVICE_ANALOGIN 1
|
||||||
#define DEVICE_ANALOGOUT 1
|
#define DEVICE_ANALOGOUT 0
|
||||||
|
|
||||||
#define DEVICE_SERIAL 1
|
#define DEVICE_SERIAL 0
|
||||||
|
|
||||||
#define DEVICE_I2C 1
|
#define DEVICE_I2C 1
|
||||||
#define DEVICE_I2CSLAVE 1
|
#define DEVICE_I2CSLAVE 0
|
||||||
|
|
||||||
#define DEVICE_SPI 1
|
#define DEVICE_SPI 1
|
||||||
#define DEVICE_SPISLAVE 1
|
#define DEVICE_SPISLAVE 1
|
||||||
|
|
||||||
#define DEVICE_CAN 1
|
#define DEVICE_CAN 0
|
||||||
|
|
||||||
#define DEVICE_RTC 1
|
#define DEVICE_RTC 0
|
||||||
|
|
||||||
#define DEVICE_ETHERNET 1
|
#define DEVICE_ETHERNET 0
|
||||||
|
|
||||||
#define DEVICE_PWMOUT 1
|
#define DEVICE_PWMOUT 0
|
||||||
|
|
||||||
#define DEVICE_SLEEP 1
|
#define DEVICE_SLEEP 0
|
||||||
|
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,11 @@ struct gpio_irq_s {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct port_s {
|
struct port_s {
|
||||||
__IO uint32_t *reg_dir;
|
__IO uint32_t *reg_mode;
|
||||||
|
__IO uint32_t *reg_in;
|
||||||
__IO uint32_t *reg_out;
|
__IO uint32_t *reg_out;
|
||||||
__I uint32_t *reg_in;
|
__IO uint16_t *reg_set;
|
||||||
|
__IO uint16_t *reg_clr;
|
||||||
PortName port;
|
PortName port;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ uint32_t gpio_set(PinName pin) {
|
||||||
uint32_t port_index = (uint32_t) pin >> 4;
|
uint32_t port_index = (uint32_t) pin >> 4;
|
||||||
|
|
||||||
// Enable GPIO peripheral clock
|
// Enable GPIO peripheral clock
|
||||||
RCC_APB1ENR |= 1 << port_index;
|
RCC->APB1ENR |= 1 << port_index;
|
||||||
|
|
||||||
pin_function(pin, 0);
|
pin_function(pin, 0);
|
||||||
return 1 << ((uint32_t) pin & 0xF);
|
return 1 << ((uint32_t) pin & 0xF);
|
||||||
|
|
@ -32,11 +32,14 @@ void gpio_init(gpio_t *obj, PinName pin, PinDirection direction) {
|
||||||
obj->pin = pin;
|
obj->pin = pin;
|
||||||
obj->mask = gpio_set(pin);
|
obj->mask = gpio_set(pin);
|
||||||
|
|
||||||
GPIO_TypeDef *port = (GPIO_TypeDef *) (GPIOA_BASE + port_index << 6);
|
uint32_t port_index = (uint32_t) pin >> 4;
|
||||||
|
|
||||||
|
GPIO_TypeDef *port_reg = (GPIO_TypeDef *) (GPIOA_BASE + (port_index << 6));
|
||||||
obj->reg_mode = &port_reg->MODER;
|
obj->reg_mode = &port_reg->MODER;
|
||||||
obj->reg_set = &port_reg->BSSRH;
|
obj->reg_set = &port_reg->BSRRH;
|
||||||
obj->reg_clr = &port_reg->BSSRL;
|
obj->reg_clr = &port_reg->BSRRL;
|
||||||
obj->reg_in = &port_reg->IDR;
|
obj->reg_in = &port_reg->IDR;
|
||||||
|
obj->reg_in = &port_reg->ODR;
|
||||||
|
|
||||||
|
|
||||||
gpio_dir(obj, direction);
|
gpio_dir(obj, direction);
|
||||||
|
|
@ -53,7 +56,7 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
|
||||||
|
|
||||||
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
void gpio_dir(gpio_t *obj, PinDirection direction) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case PIN_INPUT : pin_function(pin, 0); break;
|
case PIN_INPUT : pin_function(obj->pin, 0); break;
|
||||||
case PIN_OUTPUT: pin_function(pin, 1); break;
|
case PIN_OUTPUT: pin_function(obj->pin, 1); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ static const PinMap PinMap_I2C_SDA[] = {
|
||||||
{PF_0, I2C_2, 2, 4},
|
{PF_0, I2C_2, 2, 4},
|
||||||
{PH_5, I2C_2, 2, 4},
|
{PH_5, I2C_2, 2, 4},
|
||||||
{PH_8, I2C_3, 2, 4},
|
{PH_8, I2C_3, 2, 4},
|
||||||
{NC , NC , 0}
|
{NC , NC , 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const PinMap PinMap_I2C_SCL[] = {
|
static const PinMap PinMap_I2C_SCL[] = {
|
||||||
|
|
@ -40,7 +40,7 @@ static const PinMap PinMap_I2C_SCL[] = {
|
||||||
{PF_1, I2C_2, 2, 4},
|
{PF_1, I2C_2, 2, 4},
|
||||||
{PH_4, I2C_2, 2, 4},
|
{PH_4, I2C_2, 2, 4},
|
||||||
{PH_7, I2C_3, 2, 4},
|
{PH_7, I2C_3, 2, 4},
|
||||||
{NC , NC, 0}
|
{NC , NC, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint32_t I2C_addr_offset[2][4] = {
|
static const uint32_t I2C_addr_offset[2][4] = {
|
||||||
|
|
@ -60,16 +60,16 @@ static inline void i2c_interface_disable(i2c_t *obj) {
|
||||||
|
|
||||||
static inline void i2c_power_enable(i2c_t *obj) {
|
static inline void i2c_power_enable(i2c_t *obj) {
|
||||||
switch ((int)obj->i2c) {
|
switch ((int)obj->i2c) {
|
||||||
case I2C_1: RCC_APB1ENR |= RCC_APB1ENR_I2C1EN; break;
|
case I2C_1: RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; break;
|
||||||
case I2C_2: RCC_APB1ENR |= RCC_APB1ENR_I2C2EN; break;
|
case I2C_2: RCC->APB1ENR |= RCC_APB1ENR_I2C2EN; break;
|
||||||
case I2C_3: RCC_APB1ENR |= RCC_APB1ENR_I2C3EN; break;
|
case I2C_3: RCC->APB1ENR |= RCC_APB1ENR_I2C3EN; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void i2c_wait_status(i2c_t *obj, uint32_t sr1_mask,
|
static inline void i2c_wait_status(i2c_t *obj, uint32_t sr1_mask,
|
||||||
uint32_t sr2_mask) {
|
uint32_t sr2_mask) {
|
||||||
while (!((obj->i2c->SR1 & sr1_mask >= sr1_mask) &&
|
while (!(((obj->i2c->SR1 & sr1_mask) >= sr1_mask) &&
|
||||||
(obj->i2c->SR2 & sr2_mask == sr2_mask)));
|
((obj->i2c->SR2 & sr2_mask) == sr2_mask)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the slave address has been acknowledged
|
// Wait until the slave address has been acknowledged
|
||||||
|
|
@ -150,7 +150,7 @@ static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void i2c_do_read(i2c_t *obj, int last) {
|
static inline int i2c_do_read(i2c_t *obj, int last) {
|
||||||
if(last) {
|
if(last) {
|
||||||
// Don't acknowledge the byte
|
// Don't acknowledge the byte
|
||||||
obj->i2c->CR1 &= ~(I2C_CR1_ACK);
|
obj->i2c->CR1 &= ~(I2C_CR1_ACK);
|
||||||
|
|
@ -167,7 +167,7 @@ static inline void i2c_do_read(i2c_t *obj, int last) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_frequency(i2c_t *obj, int hz) {
|
void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
i2c_interface_disable();
|
i2c_interface_disable(obj);
|
||||||
obj->i2c->CCR &= ~I2C_CCR_CCR;
|
obj->i2c->CCR &= ~I2C_CCR_CCR;
|
||||||
if (hz > 100000) {
|
if (hz > 100000) {
|
||||||
// Fast Mode
|
// Fast Mode
|
||||||
|
|
@ -183,7 +183,7 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
result = result < 0x4 ? 0x4 : result;
|
result = result < 0x4 ? 0x4 : result;
|
||||||
obj->i2c->CCR |= result & I2C_CCR_CCR;
|
obj->i2c->CCR |= result & I2C_CCR_CCR;
|
||||||
}
|
}
|
||||||
i2c_interface_enable();
|
i2c_interface_enable(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The I2C does a read or a write as a whole operation
|
// The I2C does a read or a write as a whole operation
|
||||||
|
|
@ -201,7 +201,7 @@ void i2c_frequency(i2c_t *obj, int hz) {
|
||||||
// check for that
|
// check for that
|
||||||
|
|
||||||
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
|
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
|
||||||
int count, status;
|
int count;
|
||||||
|
|
||||||
i2c_start(obj);
|
i2c_start(obj);
|
||||||
|
|
||||||
|
|
@ -230,7 +230,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
|
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
|
||||||
int i, status;
|
int i;
|
||||||
|
|
||||||
i2c_start(obj);
|
i2c_start(obj);
|
||||||
|
|
||||||
|
|
@ -239,8 +239,8 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
|
||||||
i2c_wait_addr(obj);
|
i2c_wait_addr(obj);
|
||||||
|
|
||||||
for (i=0; i<length; i++) {
|
for (i=0; i<length; i++) {
|
||||||
status = i2c_do_write(obj, data[i], 0);
|
i2c_do_write(obj, data[i], 0);
|
||||||
i2c_wait_write(obj);
|
i2c_wait_send(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not repeated start, send stop.
|
// If not repeated start, send stop.
|
||||||
|
|
@ -260,8 +260,8 @@ int i2c_byte_read(i2c_t *obj, int last) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int i2c_byte_write(i2c_t *obj, int data) {
|
int i2c_byte_write(i2c_t *obj, int data) {
|
||||||
int status = i2c_do_write(obj, (data & 0xFF), 0);
|
i2c_do_write(obj, (data & 0xFF), 0);
|
||||||
i2c_wait_write(obj);
|
i2c_wait_send(obj);
|
||||||
|
|
||||||
// TODO: Should return whether write has been acknowledged
|
// TODO: Should return whether write has been acknowledged
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ void pin_function(PinName pin, int function) {
|
||||||
int pin_index = (pin_number & 0xF);
|
int pin_index = (pin_number & 0xF);
|
||||||
int offset = pin_index << 1;
|
int offset = pin_index << 1;
|
||||||
|
|
||||||
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + port_index << 6);
|
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6));
|
||||||
gpio->MODER &= ~(0x3 << offset);
|
gpio->MODER &= ~(0x3 << offset);
|
||||||
gpio->MODER |= function << offset;
|
gpio->MODER |= function << offset;
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +40,7 @@ void pin_alternate_function(PinName pin, int function) {
|
||||||
int pin_index = (pin_number & 0xF);
|
int pin_index = (pin_number & 0xF);
|
||||||
int offset = (pin_index & 0x7) << 2;
|
int offset = (pin_index & 0x7) << 2;
|
||||||
|
|
||||||
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + port_index << 6);
|
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6));
|
||||||
|
|
||||||
// Bottom seven pins are in AFR[0], top seven in AFR[1]
|
// Bottom seven pins are in AFR[0], top seven in AFR[1]
|
||||||
if (pin_index <= 0x7) {
|
if (pin_index <= 0x7) {
|
||||||
|
|
@ -61,7 +61,7 @@ void pin_mode(PinName pin, PinMode mode) {
|
||||||
int pin_index = (pin_number & 0xF);
|
int pin_index = (pin_number & 0xF);
|
||||||
int offset = pin_index << 1;
|
int offset = pin_index << 1;
|
||||||
|
|
||||||
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + port_index << 6);
|
GPIO_TypeDef * gpio = ((GPIO_TypeDef *) GPIOA_BASE + (port_index << 6));
|
||||||
if (mode == OpenDrain) {
|
if (mode == OpenDrain) {
|
||||||
gpio->OTYPER |= 1 << pin_index;
|
gpio->OTYPER |= 1 << pin_index;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,15 @@ void port_init(port_t *obj, PortName port, int mask, PinDirection dir) {
|
||||||
obj->port = port;
|
obj->port = port;
|
||||||
obj->mask = mask;
|
obj->mask = mask;
|
||||||
|
|
||||||
int port_index = (uint32_t) pin >> 4;
|
uint32_t port_index = (uint32_t) port;
|
||||||
|
|
||||||
GPIO_TypeDef *port_reg = (GPIO_TypeDef *)(GPIOA_BASE + port_index << 6);
|
GPIO_TypeDef *port_reg = (GPIO_TypeDef *)(GPIOA_BASE + (port_index << 6));
|
||||||
|
|
||||||
obj->reg_mode = &port_reg->MODER;
|
obj->reg_mode = &port_reg->MODER;
|
||||||
obj->reg_set = &port_reg->BSSRH;
|
obj->reg_set = &port_reg->BSRRH;
|
||||||
obj->reg_clr = &port_reg->BSSRL;
|
obj->reg_clr = &port_reg->BSRRL;
|
||||||
obj->reg_in = &port_reg->IDR;
|
obj->reg_in = &port_reg->IDR;
|
||||||
|
obj->reg_in = &port_reg->ODR;
|
||||||
|
|
||||||
port_dir(obj, dir);
|
port_dir(obj, dir);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue