Skip to content

Commit 28fa836

Browse files
committed
PIN_MAP moved to flash
1 parent 483bbe1 commit 28fa836

16 files changed

Lines changed: 286 additions & 374 deletions

File tree

STM32F4/cores/maple/ext_interrupts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) {
5151

5252
exti_trigger_mode outMode = exti_out_mode(mode);
5353

54-
exti_attach_interrupt((afio_exti_num)(PIN_MAP[pin].gpio_bit),
54+
exti_attach_interrupt((afio_exti_num)(pin&0x0F),
5555
gpio_exti_port(PIN_MAP[pin].gpio_device),
5656
handler,
5757
outMode);
@@ -66,7 +66,7 @@ void detachInterrupt(uint8 pin) {
6666
return;
6767
}
6868

69-
exti_detach_interrupt((afio_exti_num)(PIN_MAP[pin].gpio_bit));
69+
exti_detach_interrupt((afio_exti_num)(pin&0x0F));
7070
}
7171

7272
static inline exti_trigger_mode exti_out_mode(ExtIntTriggerMode mode) {

STM32F4/cores/maple/libmaple/adc.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,24 @@
4141
#include "rcc.h"
4242
#include "adc.h"
4343

44-
static adc_dev adc1 = {
44+
/** ADC1 device. */
45+
const adc_dev ADC1 = {
4546
.regs = ADC1_BASE,
4647
.clk_id = RCC_ADC1
4748
};
48-
/** ADC1 device. */
49-
const adc_dev *ADC1 = &adc1;
5049

51-
static adc_dev adc2 = {
50+
/** ADC2 device. */
51+
const adc_dev ADC2 = {
5252
.regs = ADC2_BASE,
5353
.clk_id = RCC_ADC2
5454
};
55-
/** ADC2 device. */
56-
const adc_dev *ADC2 = &adc2;
5755

5856
#ifdef STM32_HIGH_DENSITY
59-
adc_dev adc3 = {
57+
/** ADC3 device. */
58+
const adc_dev ADC3 = {
6059
.regs = ADC3_BASE,
6160
.clk_id = RCC_ADC3
6261
};
63-
/** ADC3 device. */
64-
const adc_dev *ADC3 = &adc3;
6562
#endif
6663

6764
/**
@@ -101,10 +98,10 @@ void adc_set_extsel(const adc_dev *dev, adc_extsel_event event) {
10198
* @param fn Function to call on each ADC device.
10299
*/
103100
void adc_foreach(void (*fn)(const adc_dev*)) {
104-
fn(ADC1);
105-
fn(ADC2);
101+
fn(&ADC1);
102+
fn(&ADC2);
106103
#ifdef STM32_HIGH_DENSITY
107-
fn(ADC3);
104+
fn(&ADC3);
108105
#endif
109106
}
110107

STM32F4/cores/maple/libmaple/adc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ typedef struct adc_dev {
8282
rcc_clk_id clk_id; /**< RCC clock information */
8383
} adc_dev;
8484

85-
extern const adc_dev *ADC1;
86-
extern const adc_dev *ADC2;
85+
extern const adc_dev ADC1;
86+
extern const adc_dev ADC2;
8787
#ifdef STM32_HIGH_DENSITY
88-
extern const adc_dev *ADC3;
88+
extern const adc_dev ADC3;
8989
#endif
9090

9191
/*

STM32F4/cores/maple/libmaple/gpio.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern "C"{
4646
* @brief Get a GPIO port's corresponding afio_exti_port.
4747
* @param dev GPIO device whose afio_exti_port to return.
4848
*/
49-
static inline afio_exti_port gpio_exti_port(gpio_dev *dev) {
49+
static inline afio_exti_port gpio_exti_port(const gpio_dev *dev) {
5050
return dev->exti_port;
5151
}
5252

@@ -61,18 +61,18 @@ static inline afio_exti_port gpio_exti_port(gpio_dev *dev) {
6161
*/
6262
static inline void gpio_write_pin(uint8_t pin, uint8 val) {
6363
if (val) {
64-
(PIN_MAP[pin].gpio_device)->regs->BSRRL = BIT(PIN_MAP[pin].gpio_bit);
64+
(PIN_MAP[pin].gpio_device)->regs->BSRRL = BIT(pin&0x0F);
6565
} else {
66-
(PIN_MAP[pin].gpio_device)->regs->BSRRH = BIT(PIN_MAP[pin].gpio_bit);
66+
(PIN_MAP[pin].gpio_device)->regs->BSRRH = BIT(pin&0x0F);
6767
}
6868
}
6969

7070
static inline void gpio_set_pin(uint8_t pin) {
71-
(PIN_MAP[pin].gpio_device)->regs->BSRRL = BIT(PIN_MAP[pin].gpio_bit);
71+
(PIN_MAP[pin].gpio_device)->regs->BSRRL = BIT(pin&0x0F);
7272
}
7373

7474
static inline void gpio_clear_pin(uint8_t pin) {
75-
(PIN_MAP[pin].gpio_device)->regs->BSRRH = BIT(PIN_MAP[pin].gpio_bit);
75+
(PIN_MAP[pin].gpio_device)->regs->BSRRH = BIT(pin&0x0F);
7676
}
7777

7878
/**
@@ -85,7 +85,7 @@ static inline void gpio_clear_pin(uint8_t pin) {
8585
* @return True if the pin is set, false otherwise.
8686
*/
8787
static inline uint32 gpio_read_pin(uint8_t pin) {
88-
return (PIN_MAP[pin].gpio_device)->regs->IDR & BIT(PIN_MAP[pin].gpio_bit);
88+
return (PIN_MAP[pin].gpio_device)->regs->IDR & BIT(pin&0x0F);
8989
}
9090

9191
/**
@@ -94,14 +94,14 @@ static inline uint32 gpio_read_pin(uint8_t pin) {
9494
* @param pin Pin on dev to toggle.
9595
*/
9696
static inline void gpio_toggle_pin(uint8_t pin) {
97-
(PIN_MAP[pin].gpio_device)->regs->ODR = (PIN_MAP[pin].gpio_device)->regs->ODR ^ BIT(PIN_MAP[pin].gpio_bit);
97+
(PIN_MAP[pin].gpio_device)->regs->ODR = (PIN_MAP[pin].gpio_device)->regs->ODR ^ BIT(pin&0x0F);
9898
}
9999

100100
/*
101101
* GPIO Convenience routines
102102
*/
103103

104-
extern void gpio_init(gpio_dev *dev);
104+
extern void gpio_init(const gpio_dev *dev);
105105
extern void gpio_init_all(void);
106106
extern void gpio_set_mode(uint8_t pin, gpio_pin_mode mode);
107107
extern void gpio_set_af_mode(uint8_t pin, int mode);

STM32F4/cores/maple/libmaple/gpioF4.c

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
* SOFTWARE.
2525
*****************************************************************************/
2626

27-
#ifdef STM32F4
28-
2927
/**
3028
* @file gpio.c
3129
* @brief GPIO initialization routine
@@ -38,64 +36,57 @@
3836
* GPIO devices
3937
*/
4038

41-
gpio_dev gpioa = {
39+
/** GPIO port A device. */
40+
const gpio_dev GPIOA = {
4241
.regs = GPIOA_BASE,
4342
.clk_id = RCC_GPIOA,
4443
.exti_port = AFIO_EXTI_PA,
4544
};
46-
/** GPIO port A device. */
47-
gpio_dev* const GPIOA = &gpioa;
4845

49-
gpio_dev gpiob = {
46+
/** GPIO port B device. */
47+
const gpio_dev GPIOB = {
5048
.regs = GPIOB_BASE,
5149
.clk_id = RCC_GPIOB,
5250
.exti_port = AFIO_EXTI_PB,
5351
};
54-
/** GPIO port B device. */
55-
gpio_dev* const GPIOB = &gpiob;
5652

57-
gpio_dev gpioc = {
53+
/** GPIO port C device. */
54+
const gpio_dev GPIOC = {
5855
.regs = GPIOC_BASE,
5956
.clk_id = RCC_GPIOC,
6057
.exti_port = AFIO_EXTI_PC,
6158
};
62-
/** GPIO port C device. */
63-
gpio_dev* const GPIOC = &gpioc;
6459

65-
gpio_dev gpiod = {
60+
/** GPIO port D device. */
61+
const gpio_dev GPIOD = {
6662
.regs = GPIOD_BASE,
6763
.clk_id = RCC_GPIOD,
6864
.exti_port = AFIO_EXTI_PD,
6965
};
70-
/** GPIO port D device. */
71-
gpio_dev* const GPIOD = &gpiod;
7266

7367
#ifdef STM32_HIGH_DENSITY
74-
gpio_dev gpioe = {
68+
/** GPIO port E device. */
69+
const gpio_dev GPIOE = {
7570
.regs = GPIOE_BASE,
7671
.clk_id = RCC_GPIOE,
7772
.exti_port = AFIO_EXTI_PE,
7873
};
79-
/** GPIO port E device. */
80-
gpio_dev* const GPIOE = &gpioe;
8174

8275
#if 0 // not available on LQFP 100 package
83-
gpio_dev gpiof = {
76+
/** GPIO port F device. */
77+
const gpio_dev GPIOF = {
8478
.regs = GPIOF_BASE,
8579
.clk_id = RCC_GPIOF,
8680
.exti_port = AFIO_EXTI_PF,
8781
};
88-
/** GPIO port F device. */
89-
gpio_dev* const GPIOF = &gpiof;
9082

91-
gpio_dev gpiog = {
83+
/** GPIO port G device. */
84+
const gpio_dev GPIOG = {
9285
.regs = GPIOG_BASE,
9386
.clk_id = RCC_GPIOG,
9487
.exti_port = AFIO_EXTI_PG,
9588
};
96-
/** GPIO port G device. */
97-
gpio_dev* const GPIOG = &gpiog;
98-
#endif // not available on LQFP 100 package
89+
#endif
9990
#endif
10091

10192
/*
@@ -109,7 +100,7 @@ gpio_dev* const GPIOG = &gpiog;
109100
*
110101
* @param dev GPIO device to initialize.
111102
*/
112-
void gpio_init(gpio_dev *dev) {
103+
void gpio_init(const gpio_dev *dev) {
113104
rcc_clk_enable(dev->clk_id);
114105
rcc_reset_dev(dev->clk_id);
115106
}
@@ -118,13 +109,13 @@ void gpio_init(gpio_dev *dev) {
118109
* Initialize and reset all available GPIO devices.
119110
*/
120111
void gpio_init_all(void) {
121-
gpio_init(GPIOA);
122-
gpio_init(GPIOB);
123-
gpio_init(GPIOC);
124-
gpio_init(GPIOD);
112+
gpio_init(&GPIOA);
113+
gpio_init(&GPIOB);
114+
gpio_init(&GPIOC);
115+
gpio_init(&GPIOD);
125116

126117
#ifdef STM32_HIGH_DENSITY
127-
gpio_init(GPIOE);
118+
gpio_init(&GPIOE);
128119
#if 0 // not available on LQFP 100 package
129120
gpio_init(GPIOF);
130121
gpio_init(GPIOG);
@@ -154,7 +145,7 @@ void gpio_init_all(void) {
154145
*/
155146
void gpio_set_mode(uint8_t io_pin, gpio_pin_mode mode) {
156147
gpio_reg_map *regs = (PIN_MAP[io_pin].gpio_device)->regs;
157-
uint8_t pin = PIN_MAP[io_pin].gpio_bit;
148+
uint8_t pin = io_pin&0x0f;
158149

159150
//regs->AFR[pin/8] = (regs->AFR[pin/8] & ~(15 << (4*(pin&7)))) | (((mode >> 8) & 15) << (4*(pin&7)));
160151
//gpio_set_af_mode(dev, pin, mode>>8);
@@ -175,7 +166,7 @@ void gpio_set_mode(uint8_t io_pin, gpio_pin_mode mode) {
175166
*/
176167
void gpio_set_af_mode(uint8_t io_pin, int mode) {
177168
gpio_reg_map *regs = (PIN_MAP[io_pin].gpio_device)->regs;
178-
uint8_t pin = PIN_MAP[io_pin].gpio_bit;
169+
uint8_t pin = io_pin&0x0F;
179170

180171
regs->AFR[pin>>3] = (regs->AFR[pin>>3] & ~(15 << ((pin&7)<<2))) | (((mode >> 0) & 15) << ((pin&7)<<2));
181172
}
@@ -226,5 +217,3 @@ void afio_remap(afio_remap_peripheral remapping) {
226217
}
227218
}
228219
#endif
229-
230-
#endif

STM32F4/cores/maple/libmaple/gpio_def.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,12 @@ typedef struct gpio_dev {
8989
afio_exti_port exti_port; /**< AFIO external interrupt port value */
9090
} gpio_dev;
9191

92-
extern gpio_dev gpioa;
93-
extern gpio_dev* const GPIOA;
94-
extern gpio_dev gpiob;
95-
extern gpio_dev* const GPIOB;
96-
extern gpio_dev gpioc;
97-
extern gpio_dev* const GPIOC;
98-
extern gpio_dev gpiod;
99-
extern gpio_dev* const GPIOD;
92+
extern const gpio_dev GPIOA;
93+
extern const gpio_dev GPIOB;
94+
extern const gpio_dev GPIOC;
95+
extern const gpio_dev GPIOD;
10096
#ifdef STM32_HIGH_DENSITY
101-
extern gpio_dev gpioe;
102-
extern gpio_dev* const GPIOE;
97+
extern const gpio_dev GPIOE;
10398
#if 0 // not available on LQFP 100 package
10499
extern gpio_dev gpiof;
105100
extern gpio_dev* const GPIOF;

STM32F4/cores/maple/libmaple/spi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ typedef struct spi_dev {
213213

214214
void spi_init(spi_dev *dev);
215215

216-
struct gpio_dev;
217216
/**
218217
* @brief Configure GPIO bit modes for use as a SPI port's pins.
219218
*

STM32F4/cores/maple/libmaple/timer.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
/* Update only. */
4545
#define NR_BAS_HANDLERS 1
4646

47-
static timer_dev timer1 = {
47+
timer_dev timer1 = {
4848
.regs = { .adv = TIMER1_BASE },
4949
.clk_id = RCC_TIMER1,
5050
.type = TIMER_ADVANCED,
@@ -53,7 +53,7 @@ static timer_dev timer1 = {
5353
/** Timer 1 device (advanced) */
5454
timer_dev *TIMER1 = &timer1;
5555

56-
static timer_dev timer2 = {
56+
timer_dev timer2 = {
5757
.regs = { .gen = TIMER2_BASE },
5858
.clk_id = RCC_TIMER2,
5959
.type = TIMER_GENERAL,
@@ -62,7 +62,7 @@ static timer_dev timer2 = {
6262
/** Timer 2 device (general-purpose) */
6363
timer_dev *TIMER2 = &timer2;
6464

65-
static timer_dev timer3 = {
65+
timer_dev timer3 = {
6666
.regs = { .gen = TIMER3_BASE },
6767
.clk_id = RCC_TIMER3,
6868
.type = TIMER_GENERAL,
@@ -71,7 +71,7 @@ static timer_dev timer3 = {
7171
/** Timer 3 device (general-purpose) */
7272
timer_dev *TIMER3 = &timer3;
7373

74-
static timer_dev timer4 = {
74+
timer_dev timer4 = {
7575
.regs = { .gen = TIMER4_BASE },
7676
.clk_id = RCC_TIMER4,
7777
.type = TIMER_GENERAL,
@@ -81,7 +81,7 @@ static timer_dev timer4 = {
8181
timer_dev *TIMER4 = &timer4;
8282

8383
#ifdef STM32_HIGH_DENSITY
84-
static timer_dev timer5 = {
84+
timer_dev timer5 = {
8585
.regs = { .gen = TIMER5_BASE },
8686
.clk_id = RCC_TIMER5,
8787
.type = TIMER_GENERAL,
@@ -90,7 +90,7 @@ static timer_dev timer5 = {
9090
/** Timer 5 device (general-purpose) */
9191
timer_dev *TIMER5 = &timer5;
9292

93-
static timer_dev timer6 = {
93+
timer_dev timer6 = {
9494
.regs = { .bas = TIMER6_BASE },
9595
.clk_id = RCC_TIMER6,
9696
.type = TIMER_BASIC,
@@ -99,7 +99,7 @@ static timer_dev timer6 = {
9999
/** Timer 6 device (basic) */
100100
timer_dev *TIMER6 = &timer6;
101101

102-
static timer_dev timer7 = {
102+
timer_dev timer7 = {
103103
.regs = { .bas = TIMER7_BASE },
104104
.clk_id = RCC_TIMER7,
105105
.type = TIMER_BASIC,
@@ -108,7 +108,7 @@ static timer_dev timer7 = {
108108
/** Timer 7 device (basic) */
109109
timer_dev *TIMER7 = &timer7;
110110

111-
static timer_dev timer8 = {
111+
timer_dev timer8 = {
112112
.regs = { .adv = TIMER8_BASE },
113113
.clk_id = RCC_TIMER8,
114114
.type = TIMER_ADVANCED,

STM32F4/cores/maple/usb_serial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ uint8 USBSerial::pending(void) {
134134
return usbGetPending();
135135
}
136136

137-
uint8 USBSerial::isConnected(void) {
137+
USBSerial::operator bool() {
138138
return usbIsConnected() && usbIsConfigured();
139139
}
140140

0 commit comments

Comments
 (0)