mirror of https://github.com/ARMmbed/mbed-os.git
[NUCLEO_L152RE] Update xxx_free() functions + typo
parent
48a53c4be0
commit
b968150d2f
|
@ -54,8 +54,8 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
// Configure GPIO
|
||||
pinmap_pinout(pin, PinMap_DAC);
|
||||
|
||||
// Save the channel for the write and read functions
|
||||
obj->channel = pin;
|
||||
// Save the pin for future use
|
||||
obj->pin = pin;
|
||||
|
||||
// Enable DAC clock
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
|
||||
|
@ -66,11 +66,11 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
|
||||
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
|
||||
|
||||
if (obj->channel == PA_4) {
|
||||
if (obj->pin == PA_4) {
|
||||
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
|
||||
DAC_Cmd(DAC_Channel_1, ENABLE);
|
||||
}
|
||||
if (obj->channel == PA_5) {
|
||||
if (obj->pin == PA_5) {
|
||||
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
|
||||
DAC_Cmd(DAC_Channel_2, ENABLE);
|
||||
}
|
||||
|
@ -79,22 +79,24 @@ void analogout_init(dac_t *obj, PinName pin) {
|
|||
}
|
||||
|
||||
void analogout_free(dac_t *obj) {
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
static inline void dac_write(dac_t *obj, uint16_t value) {
|
||||
if (obj->channel == PA_4) {
|
||||
if (obj->pin == PA_4) {
|
||||
DAC_SetChannel1Data(DAC_Align_12b_R, value);
|
||||
}
|
||||
if (obj->channel == PA_5) {
|
||||
if (obj->pin == PA_5) {
|
||||
DAC_SetChannel2Data(DAC_Align_12b_R, value);
|
||||
}
|
||||
}
|
||||
|
||||
static inline int dac_read(dac_t *obj) {
|
||||
if (obj->channel == PA_4) {
|
||||
if (obj->pin == PA_4) {
|
||||
return (int)DAC_GetDataOutputValue(DAC_Channel_1);
|
||||
}
|
||||
if (obj->channel == PA_5) {
|
||||
if (obj->pin == PA_5) {
|
||||
return (int)DAC_GetDataOutputValue(DAC_Channel_2);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -317,10 +317,9 @@ int i2c_slave_receive(i2c_t *obj) {
|
|||
uint32_t event;
|
||||
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
|
||||
|
||||
event = I2C_GetLastEvent( i2c );
|
||||
if(event != 0)
|
||||
{
|
||||
switch(event){
|
||||
event = I2C_GetLastEvent(i2c);
|
||||
if (event != 0) {
|
||||
switch (event) {
|
||||
case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:
|
||||
retValue = WriteAddressed;
|
||||
break;
|
||||
|
@ -336,21 +335,21 @@ int i2c_slave_receive(i2c_t *obj) {
|
|||
}
|
||||
|
||||
// clear ADDR
|
||||
if((retValue == WriteAddressed) || (retValue == ReadAddressed)){
|
||||
if ((retValue == WriteAddressed) || (retValue == ReadAddressed)) {
|
||||
i2c->SR1;// read status register 1
|
||||
i2c->SR2;// read status register 2
|
||||
}
|
||||
// clear stopf
|
||||
if(I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) {
|
||||
if (I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) {
|
||||
i2c->SR1;// read status register 1
|
||||
I2C_Cmd(i2c, ENABLE);
|
||||
}
|
||||
// clear AF
|
||||
if(I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) {
|
||||
if (I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) {
|
||||
I2C_ClearFlag(i2c, I2C_FLAG_AF);
|
||||
}
|
||||
}
|
||||
return(retValue);
|
||||
return (retValue);
|
||||
}
|
||||
|
||||
int i2c_slave_read(i2c_t *obj, char *data, int length) {
|
||||
|
|
|
@ -60,7 +60,7 @@ struct analogin_s {
|
|||
|
||||
struct dac_s {
|
||||
DACName dac;
|
||||
PinName channel;
|
||||
PinName pin;
|
||||
};
|
||||
|
||||
struct serial_s {
|
||||
|
@ -70,6 +70,8 @@ struct serial_s {
|
|||
uint32_t databits;
|
||||
uint32_t stopbits;
|
||||
uint32_t parity;
|
||||
PinName pin_tx;
|
||||
PinName pin_rx;
|
||||
};
|
||||
|
||||
struct spi_s {
|
||||
|
@ -80,6 +82,10 @@ struct spi_s {
|
|||
uint32_t mode;
|
||||
uint32_t nss;
|
||||
uint32_t br_presc;
|
||||
PinName pin_miso;
|
||||
PinName pin_mosi;
|
||||
PinName pin_sclk;
|
||||
PinName pin_ssel;
|
||||
};
|
||||
|
||||
struct i2c_s {
|
||||
|
|
|
@ -102,8 +102,8 @@ void pwmout_init(pwmout_t* obj, PinName pin) {
|
|||
}
|
||||
|
||||
void pwmout_free(pwmout_t* obj) {
|
||||
TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
|
||||
TIM_DeInit(tim);
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
void pwmout_write(pwmout_t* obj, float value) {
|
||||
|
|
|
@ -99,18 +99,23 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
// Enable USART clock
|
||||
if (obj->uart == UART_1) {
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
obj->index = 0;
|
||||
}
|
||||
if (obj->uart == UART_2) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
obj->index = 1;
|
||||
}
|
||||
if (obj->uart == UART_3) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
obj->index = 2;
|
||||
}
|
||||
if (obj->uart == UART_4) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
obj->index = 3;
|
||||
}
|
||||
if (obj->uart == UART_5) {
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
obj->index = 4;
|
||||
}
|
||||
|
||||
// Configure the UART pins
|
||||
|
@ -125,14 +130,10 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
obj->stopbits = USART_StopBits_1;
|
||||
obj->parity = USART_Parity_No;
|
||||
|
||||
init_usart(obj);
|
||||
obj->pin_tx = tx;
|
||||
obj->pin_rx = rx;
|
||||
|
||||
// The index is used by irq
|
||||
if (obj->uart == UART_1) obj->index = 0;
|
||||
if (obj->uart == UART_2) obj->index = 1;
|
||||
if (obj->uart == UART_3) obj->index = 2;
|
||||
if (obj->uart == UART_4) obj->index = 3;
|
||||
if (obj->uart == UART_5) obj->index = 4;
|
||||
init_usart(obj);
|
||||
|
||||
// For stdio management
|
||||
if (obj->uart == STDIO_UART) {
|
||||
|
@ -142,6 +143,37 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
|
|||
}
|
||||
|
||||
void serial_free(serial_t *obj) {
|
||||
// Reset UART and disable clock
|
||||
if (obj->uart == UART_1) {
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE);
|
||||
}
|
||||
if (obj->uart == UART_2) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, DISABLE);
|
||||
}
|
||||
if (obj->uart == UART_3) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, DISABLE);
|
||||
}
|
||||
if (obj->uart == UART_4) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, DISABLE);
|
||||
}
|
||||
if (obj->uart == UART_5) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, DISABLE);
|
||||
}
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_tx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_rx, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
|
||||
serial_irq_ids[obj->index] = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,11 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
obj->cpha = SPI_CPHA_1Edge;
|
||||
obj->br_presc = SPI_BaudRatePrescaler_256;
|
||||
|
||||
obj->pin_miso = miso;
|
||||
obj->pin_mosi = mosi;
|
||||
obj->pin_sclk = sclk;
|
||||
obj->pin_ssel = ssel;
|
||||
|
||||
if (ssel == NC) { // Master
|
||||
obj->mode = SPI_Mode_Master;
|
||||
obj->nss = SPI_NSS_Soft;
|
||||
|
@ -145,8 +150,30 @@ void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel
|
|||
}
|
||||
|
||||
void spi_free(spi_t *obj) {
|
||||
SPI_TypeDef *spi = (SPI_TypeDef *)(obj->spi);
|
||||
SPI_I2S_DeInit(spi);
|
||||
// Reset SPI and disable clock
|
||||
if (obj->spi == SPI_1) {
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, ENABLE);
|
||||
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1, DISABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, DISABLE);
|
||||
}
|
||||
|
||||
if (obj->spi == SPI_2) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI2, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, DISABLE);
|
||||
}
|
||||
|
||||
if (obj->spi == SPI_3) {
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
|
||||
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, DISABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, DISABLE);
|
||||
}
|
||||
|
||||
// Configure GPIOs
|
||||
pin_function(obj->pin_miso, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_mosi, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_sclk, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
pin_function(obj->pin_ssel, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
|
||||
}
|
||||
|
||||
void spi_format(spi_t *obj, int bits, int mode, int slave) {
|
||||
|
|
Loading…
Reference in New Issue