Skip to content

Commit 12e1e7c

Browse files
nvlsianpuadbridge
authored andcommitted
code formating, CR changes corrected spi_init() to properly handle re-initialization… #3842
1 parent 6501389 commit 12e1e7c

File tree

14 files changed

+711
-372
lines changed

14 files changed

+711
-372
lines changed

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840/PeripheralNames.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,33 @@ extern "C" {
4949
#define STDIO_UART_RX RX_PIN_NUMBER
5050
#define STDIO_UART UART_0
5151

52-
typedef enum {
52+
typedef enum
53+
{
5354
UART_0 = (int)NRF_UART0_BASE
5455
} UARTName;
5556

5657

57-
typedef enum {
58+
typedef enum
59+
{
5860
SPI_0 = (int)NRF_SPI0_BASE,
5961
SPI_1 = (int)NRF_SPI1_BASE,
6062
SPIS = (int)NRF_SPIS1_BASE
6163
} SPIName;
6264

63-
typedef enum {
65+
typedef enum
66+
{
6467
PWM_1 = 0,
6568
PWM_2
6669
} PWMName;
6770

68-
typedef enum {
71+
typedef enum
72+
{
6973
I2C_0 = (int)NRF_TWI0_BASE,
7074
I2C_1 = (int)NRF_TWI1_BASE
7175
} I2CName;
7276

73-
typedef enum {
77+
typedef enum
78+
{
7479
ADC0_0 = (int)0
7580
} ADCName;
7681

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/TARGET_MCU_NRF52840/PortNames.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
extern "C" {
4444
#endif
4545

46-
typedef enum {
46+
typedef enum
47+
{
4748
Port0 = 0, //GPIO pins 0-31 -> 0.0-0.31
4849
Port1 = 1 //GPIO pins 32-47 -> 1.0-1.15
4950
} PortName;

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/gpio_api.c

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
#error not recognized gpio count for mcu
3030
#endif
3131

32-
typedef struct {
32+
typedef struct
33+
{
3334
bool used_as_gpio : 1;
3435
PinDirection direction : 1;
3536
bool init_high : 1;
@@ -45,29 +46,31 @@ typedef struct {
4546
typedef uint32_t gpio_mask_t;
4647
#endif
4748

48-
gpio_mask_t m_gpio_initialized;
49-
gpio_cfg_t m_gpio_cfg[GPIO_PIN_COUNT];
49+
static gpio_mask_t m_gpio_initialized;
50+
static gpio_cfg_t m_gpio_cfg[GPIO_PIN_COUNT];
5051

5152

5253
/***********
5354
GPIO IRQ
5455
***********/
5556

5657
static gpio_irq_handler m_irq_handler;
57-
static uint32_t m_channel_ids[GPIO_PIN_COUNT] = {0};
58-
gpio_mask_t m_gpio_irq_enabled;
58+
static uint32_t m_channel_ids[GPIO_PIN_COUNT] = {0};
59+
static gpio_mask_t m_gpio_irq_enabled;
5960

6061

6162
static void gpiote_irq_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
6263
{
6364
nrf_gpio_pin_sense_t sense = nrf_gpio_pin_sense_get(pin);
6465
gpio_irq_event event = (sense == NRF_GPIO_PIN_SENSE_LOW) ? IRQ_RISE : IRQ_FALL;
65-
66-
if (m_gpio_irq_enabled & ((gpio_mask_t)1 << pin)) {
66+
67+
if (m_gpio_irq_enabled & ((gpio_mask_t)1 << pin))
68+
{
6769
if (((event == IRQ_RISE) && m_gpio_cfg[pin].irq_rise)
68-
|| ((event == IRQ_FALL) && m_gpio_cfg[pin].irq_fall)) {
69-
m_irq_handler(m_channel_ids[pin], event);
70-
}
70+
|| ((event == IRQ_FALL) && m_gpio_cfg[pin].irq_fall))
71+
{
72+
m_irq_handler(m_channel_ids[pin], event);
73+
}
7174
}
7275
}
7376

@@ -76,7 +79,8 @@ void GPIOTE_IRQHandler(void);// exported from nrf_drv_gpiote.c
7679
void gpio_init(gpio_t *obj, PinName pin)
7780
{
7881
obj->pin = pin;
79-
if (pin == (PinName)NC) {
82+
if (pin == (PinName)NC)
83+
{
8084
return;
8185
}
8286
MBED_ASSERT((uint32_t)pin < GPIO_PIN_COUNT);
@@ -92,37 +96,46 @@ void gpio_init(gpio_t *obj, PinName pin)
9296
int gpio_read(gpio_t *obj)
9397
{
9498
MBED_ASSERT(obj->pin != (PinName)NC);
95-
if (m_gpio_cfg[obj->pin].direction == PIN_OUTPUT) {
99+
if (m_gpio_cfg[obj->pin].direction == PIN_OUTPUT)
100+
{
96101
return (nrf_gpio_pin_out_read(obj->pin) ? 1 : 0);
97-
} else {
102+
}
103+
else
104+
{
98105
return nrf_gpio_pin_read(obj->pin);
99106
}
100107
}
101108

102109
static void gpiote_pin_uninit(uint8_t pin)
103110
{
104-
if (m_gpio_initialized & ((gpio_mask_t)1 << pin)) {
105-
if ((m_gpio_cfg[pin].direction == PIN_OUTPUT) && (!m_gpio_cfg[pin].used_as_irq)) {
111+
if (m_gpio_initialized & ((gpio_mask_t)1 << pin))
112+
{
113+
if ((m_gpio_cfg[pin].direction == PIN_OUTPUT) && (!m_gpio_cfg[pin].used_as_irq))
114+
{
106115
nrf_drv_gpiote_out_uninit(pin);
107116
}
108-
else {
117+
else
118+
{
109119
nrf_drv_gpiote_in_uninit(pin);
110120
}
111121
}
112122
}
113123

114124
static void gpio_apply_config(uint8_t pin)
115125
{
116-
if (m_gpio_cfg[pin].used_as_gpio || m_gpio_cfg[pin].used_as_irq) {
126+
if (m_gpio_cfg[pin].used_as_gpio || m_gpio_cfg[pin].used_as_irq)
127+
{
117128
if ((m_gpio_cfg[pin].direction == PIN_INPUT)
118-
|| (m_gpio_cfg[pin].used_as_irq)) {
129+
|| (m_gpio_cfg[pin].used_as_irq))
130+
{
119131
//Configure as input.
120132
nrf_drv_gpiote_in_config_t cfg;
121133

122134
cfg.hi_accuracy = false;
123135
cfg.is_watcher = false;
124136
cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE;
125-
if (m_gpio_cfg[pin].used_as_irq) {
137+
if (m_gpio_cfg[pin].used_as_irq)
138+
{
126139
cfg.pull = NRF_GPIO_PIN_PULLUP;
127140
nrf_drv_gpiote_in_init(pin, &cfg, gpiote_irq_handler);
128141
if ((m_gpio_irq_enabled & ((gpio_mask_t)1 << pin))
@@ -131,8 +144,10 @@ static void gpio_apply_config(uint8_t pin)
131144
nrf_drv_gpiote_in_event_enable(pin, true);
132145
}
133146
}
134-
else {
135-
switch(m_gpio_cfg[pin].pull) {
147+
else
148+
{
149+
switch (m_gpio_cfg[pin].pull)
150+
{
136151
case PullUp:
137152
cfg.pull = NRF_GPIO_PIN_PULLUP;
138153
break;
@@ -146,22 +161,24 @@ static void gpio_apply_config(uint8_t pin)
146161
nrf_drv_gpiote_in_init(pin, &cfg, NULL);
147162
}
148163
}
149-
else {
164+
else
165+
{
150166
// Configure as output.
151167
nrf_drv_gpiote_out_config_t cfg = GPIOTE_CONFIG_OUT_SIMPLE(m_gpio_cfg[pin].init_high);
152168
nrf_drv_gpiote_out_init(pin, &cfg);
153169
}
154170
m_gpio_initialized |= ((gpio_mask_t)1 << pin);
155171
}
156-
else {
172+
else
173+
{
157174
m_gpio_initialized &= ~((gpio_mask_t)1 << pin);
158175
}
159176
}
160177

161178

162179
void gpio_mode(gpio_t *obj, PinMode mode)
163180
{
164-
MBED_ASSERT(obj->pin <= GPIO_PIN_COUNT);
181+
MBED_ASSERT(obj->pin != (PinName)NC);
165182

166183
gpiote_pin_uninit(obj->pin); // try to uninitialize gpio before a change.
167184

@@ -172,7 +189,7 @@ void gpio_mode(gpio_t *obj, PinMode mode)
172189

173190
void gpio_dir(gpio_t *obj, PinDirection direction)
174191
{
175-
MBED_ASSERT(obj->pin <= GPIO_PIN_COUNT);
192+
MBED_ASSERT(obj->pin != (PinName)NC);
176193

177194
gpiote_pin_uninit(obj->pin); // try to uninitialize gpio before a change.
178195

@@ -187,7 +204,8 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
187204

188205
int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
189206
{
190-
if (pin == NC) {
207+
if (pin == NC)
208+
{
191209
return -1;
192210
}
193211
MBED_ASSERT((uint32_t)pin < GPIO_PIN_COUNT);
@@ -223,19 +241,25 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
223241
(m_gpio_irq_enabled & ((gpio_mask_t)1 << obj->ch)) &&
224242
(cfg->irq_rise || cfg->irq_fall);
225243

226-
if (event == IRQ_RISE) {
244+
if (event == IRQ_RISE)
245+
{
227246
cfg->irq_rise = enable ? true : false;
228247
}
229-
else if (event == IRQ_FALL) {
248+
else if (event == IRQ_FALL)
249+
{
230250
cfg->irq_fall = enable ? true : false;
231251
}
232252

233253
bool irq_enabled_after = cfg->irq_rise || cfg->irq_fall;
234254

235-
if (irq_enabled_before != irq_enabled_after) {
236-
if (irq_enabled_after) {
255+
if (irq_enabled_before != irq_enabled_after)
256+
{
257+
if (irq_enabled_after)
258+
{
237259
gpio_irq_enable(obj);
238-
} else {
260+
}
261+
else
262+
{
239263
gpio_irq_disable(obj);
240264
}
241265
}
@@ -245,7 +269,8 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
245269
void gpio_irq_enable(gpio_irq_t *obj)
246270
{
247271
m_gpio_irq_enabled |= ((gpio_mask_t)1 << obj->ch);
248-
if (m_gpio_cfg[obj->ch].irq_rise || m_gpio_cfg[obj->ch].irq_fall) {
272+
if (m_gpio_cfg[obj->ch].irq_rise || m_gpio_cfg[obj->ch].irq_fall)
273+
{
249274
nrf_drv_gpiote_in_event_enable(obj->ch, true);
250275
}
251276
}

targets/TARGET_NORDIC/TARGET_NRF5_SDK13/gpio_object.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,26 @@
2424
extern "C" {
2525
#endif
2626

27-
typedef struct {
27+
typedef struct
28+
{
2829
PinName pin;
2930
} gpio_t;
3031

31-
static inline void gpio_write(gpio_t *obj, int value) {
32+
static inline void gpio_write(gpio_t *obj, int value)
33+
{
3234
MBED_ASSERT(obj->pin != (PinName)NC);
33-
if (value) {
35+
if (value)
36+
{
3437
nrf_gpio_pin_set(obj->pin);
35-
} else {
38+
}
39+
else
40+
{
3641
nrf_gpio_pin_clear(obj->pin);
3742
}
3843
}
3944

40-
static inline int gpio_is_connected(const gpio_t *obj) {
45+
static inline int gpio_is_connected(const gpio_t *obj)
46+
{
4147
return obj->pin != (PinName)NC;
4248
}
4349

0 commit comments

Comments
 (0)