aboutsummaryrefslogtreecommitdiffstats
path: root/wirish
diff options
context:
space:
mode:
Diffstat (limited to 'wirish')
-rw-r--r--wirish/boards.cpp (renamed from wirish/wirish.cpp)27
-rw-r--r--wirish/boards.h16
-rw-r--r--wirish/boards/maple.cpp78
-rw-r--r--wirish/boards/maple_RET6.cpp81
-rw-r--r--wirish/boards/maple_mini.cpp68
-rw-r--r--wirish/boards/maple_native.cpp202
-rw-r--r--wirish/ext_interrupts.cpp4
-rw-r--r--wirish/io.h33
-rw-r--r--wirish/pwm.cpp2
-rw-r--r--wirish/rules.mk4
-rw-r--r--wirish/wirish.h2
-rw-r--r--wirish/wirish_analog.cpp9
-rw-r--r--wirish/wirish_digital.cpp28
-rw-r--r--wirish/wirish_types.h26
14 files changed, 304 insertions, 276 deletions
diff --git a/wirish/wirish.cpp b/wirish/boards.cpp
index aeed089..17f47c6 100644
--- a/wirish/wirish.cpp
+++ b/wirish/boards.cpp
@@ -23,7 +23,7 @@
*****************************************************************************/
/**
- * @brief Generic Maple board initialization.
+ * @brief Generic board initialization routines.
*
* By default, we bring up all Maple boards to 72MHz, clocked off the
* PLL, driven by the 8MHz external crystal. AHB and APB2 are clocked
@@ -47,7 +47,13 @@ static void setupADC(void);
static void setupTimers(void);
/**
- * Board-wide initialization function. Called before main().
+ * @brief Generic board initialization function.
+ *
+ * This function is called before main(). It ensures that the clocks
+ * and peripherals are configured properly for use with wirish, then
+ * calls boardInit().
+ *
+ * @see boardInit()
*/
void init(void) {
setupFlash();
@@ -82,10 +88,10 @@ static void setupClocks() {
rcc_set_prescaler(RCC_PRESCALER_APB2, RCC_APB2_HCLK_DIV_1);
}
-/* TODO initialize more ADCs on high density boards. */
+static void adcDefaultConfig(const adc_dev* dev);
+
static void setupADC() {
- adc_init(ADC1, 0);
- adc_set_sample_rate(ADC1, ADC_SMPR_55_5); // for high impedance inputs
+ adc_foreach(adcDefaultConfig);
}
static void timerDefaultConfig(timer_dev*);
@@ -94,6 +100,17 @@ static void setupTimers() {
timer_foreach(timerDefaultConfig);
}
+static void adcDefaultConfig(const adc_dev *dev) {
+ adc_init(dev);
+
+ adc_set_extsel(dev, ADC_SWSTART);
+ adc_set_exttrig(dev, true);
+
+ adc_enable(dev);
+ adc_calibrate(dev);
+ adc_set_sample_rate(dev, ADC_SMPR_55_5);
+}
+
static void timerDefaultConfig(timer_dev *dev) {
timer_adv_reg_map *regs = (dev->regs).adv;
const uint16 full_overflow = 0xFFFF;
diff --git a/wirish/boards.h b/wirish/boards.h
index b72609d..3d023ae 100644
--- a/wirish/boards.h
+++ b/wirish/boards.h
@@ -60,12 +60,22 @@ enum {
D106, D107, D108, D109, D110, D111, };
/**
- * @brief Maps each pin to a corresponding struct stm32_pin_info.
- * @see struct stm32_pin_info
+ * @brief Maps each Maple pin to a corresponding stm32_pin_info.
+ * @see stm32_pin_info
*/
extern stm32_pin_info PIN_MAP[];
-/** Board-specific initialization function. */
+void init(void);
+
+/**
+ * @brief Board-specific initialization function.
+ *
+ * This function is called from init() after all generic board
+ * initialization has been performed. Each board is required to
+ * define its own.
+ *
+ * @see init()
+ */
extern void boardInit(void);
#ifdef BOARD_maple
diff --git a/wirish/boards/maple.cpp b/wirish/boards/maple.cpp
index cebd222..ba2261b 100644
--- a/wirish/boards/maple.cpp
+++ b/wirish/boards/maple.cpp
@@ -44,51 +44,51 @@ stm32_pin_info PIN_MAP[NR_GPIO_PINS] = {
/* Top header */
- {GPIOA, TIMER2, 3, 4, 3}, /* D0/PA3 */
- {GPIOA, TIMER2, 2, 3, 2}, /* D1/PA2 */
- {GPIOA, TIMER2, 0, 1, 0}, /* D2/PA0 */
- {GPIOA, TIMER2, 1, 2, 1}, /* D3/PA1 */
- {GPIOB, NULL, 5, 0, ADCx}, /* D4/PB5 */
- {GPIOB, TIMER4, 6, 1, ADCx}, /* D5/PB6 */
- {GPIOA, TIMER1, 8, 1, ADCx}, /* D6/PA8 */
- {GPIOA, TIMER1, 9, 2, ADCx}, /* D7/PA9 */
- {GPIOA, TIMER1, 10, 3, ADCx}, /* D8/PA10 */
- {GPIOB, TIMER4, 7, 2, ADCx}, /* D9/PB7 */
- {GPIOA, NULL, 4, 0, 4}, /* D10/PA4 */
- {GPIOA, TIMER3, 7, 2, 7}, /* D11/PA7 */
- {GPIOA, TIMER3, 6, 1, 6}, /* D12/PA6 */
- {GPIOA, NULL, 5, 0, 5}, /* D13/PA5 (LED) */
- {GPIOB, TIMER4, 8, 3, ADCx}, /* D14/PB8 */
+ {GPIOA, TIMER2, ADC1, 3, 4, 3}, /* D0/PA3 */
+ {GPIOA, TIMER2, ADC1, 2, 3, 2}, /* D1/PA2 */
+ {GPIOA, TIMER2, ADC1, 0, 1, 0}, /* D2/PA0 */
+ {GPIOA, TIMER2, ADC1, 1, 2, 1}, /* D3/PA1 */
+ {GPIOB, NULL, NULL, 5, 0, ADCx}, /* D4/PB5 */
+ {GPIOB, TIMER4, NULL, 6, 1, ADCx}, /* D5/PB6 */
+ {GPIOA, TIMER1, NULL, 8, 1, ADCx}, /* D6/PA8 */
+ {GPIOA, TIMER1, NULL, 9, 2, ADCx}, /* D7/PA9 */
+ {GPIOA, TIMER1, NULL, 10, 3, ADCx}, /* D8/PA10 */
+ {GPIOB, TIMER4, NULL, 7, 2, ADCx}, /* D9/PB7 */
+ {GPIOA, NULL, ADC1, 4, 0, 4}, /* D10/PA4 */
+ {GPIOA, TIMER3, ADC1, 7, 2, 7}, /* D11/PA7 */
+ {GPIOA, TIMER3, ADC1, 6, 1, 6}, /* D12/PA6 */
+ {GPIOA, NULL, ADC1, 5, 0, 5}, /* D13/PA5 (LED) */
+ {GPIOB, TIMER4, NULL, 8, 3, ADCx}, /* D14/PB8 */
/* Little header */
- {GPIOC, NULL, 0, 0, 10}, /* D15/PC0 */
- {GPIOC, NULL, 1, 0, 11}, /* D16/PC1 */
- {GPIOC, NULL, 2, 0, 12}, /* D17/PC2 */
- {GPIOC, NULL, 3, 0, 13}, /* D18/PC3 */
- {GPIOC, NULL, 4, 0, 14}, /* D19/PC4 */
- {GPIOC, NULL, 5, 0, 15}, /* D20/PC5 */
+ {GPIOC, NULL, ADC1, 0, 0, 10}, /* D15/PC0 */
+ {GPIOC, NULL, ADC1, 1, 0, 11}, /* D16/PC1 */
+ {GPIOC, NULL, ADC1, 2, 0, 12}, /* D17/PC2 */
+ {GPIOC, NULL, ADC1, 3, 0, 13}, /* D18/PC3 */
+ {GPIOC, NULL, ADC1, 4, 0, 14}, /* D19/PC4 */
+ {GPIOC, NULL, ADC1, 5, 0, 15}, /* D20/PC5 */
/* External header */
- {GPIOC, NULL, 13, 0, ADCx}, /* D21/PC13 */
- {GPIOC, NULL, 14, 0, ADCx}, /* D22/PC14 */
- {GPIOC, NULL, 15, 0, ADCx}, /* D23/PC15 */
- {GPIOB, TIMER4, 9, 4, ADCx}, /* D24/PB9 */
- {GPIOD, NULL, 2, 0, ADCx}, /* D25/PD2 */
- {GPIOC, NULL, 10, 0, ADCx}, /* D26/PC10 */
- {GPIOB, TIMER3, 0, 3, 8}, /* D27/PB0 */
- {GPIOB, TIMER3, 1, 4, 9}, /* D28/PB1 */
- {GPIOB, NULL, 10, 0, ADCx}, /* D29/PB10 */
- {GPIOB, NULL, 11, 0, ADCx}, /* D30/PB11 */
- {GPIOB, NULL, 12, 0, ADCx}, /* D31/PB12 */
- {GPIOB, NULL, 13, 0, ADCx}, /* D32/PB13 */
- {GPIOB, NULL, 14, 0, ADCx}, /* D33/PB14 */
- {GPIOB, NULL, 15, 0, ADCx}, /* D34/PB15 */
- {GPIOC, NULL, 6, 0, ADCx}, /* D35/PC6 */
- {GPIOC, NULL, 7, 0, ADCx}, /* D36/PC7 */
- {GPIOC, NULL, 8, 0, ADCx}, /* D37/PC8 */
- {GPIOC, NULL, 9, 0, ADCx} /* D38/PC9 (BUT) */
+ {GPIOC, NULL, NULL, 13, 0, ADCx}, /* D21/PC13 */
+ {GPIOC, NULL, NULL, 14, 0, ADCx}, /* D22/PC14 */
+ {GPIOC, NULL, NULL, 15, 0, ADCx}, /* D23/PC15 */
+ {GPIOB, TIMER4, NULL, 9, 4, ADCx}, /* D24/PB9 */
+ {GPIOD, NULL, NULL, 2, 0, ADCx}, /* D25/PD2 */
+ {GPIOC, NULL, NULL, 10, 0, ADCx}, /* D26/PC10 */
+ {GPIOB, TIMER3, ADC1, 0, 3, 8}, /* D27/PB0 */
+ {GPIOB, TIMER3, ADC1, 1, 4, 9}, /* D28/PB1 */
+ {GPIOB, NULL, NULL, 10, 0, ADCx}, /* D29/PB10 */
+ {GPIOB, NULL, NULL, 11, 0, ADCx}, /* D30/PB11 */
+ {GPIOB, NULL, NULL, 12, 0, ADCx}, /* D31/PB12 */
+ {GPIOB, NULL, NULL, 13, 0, ADCx}, /* D32/PB13 */
+ {GPIOB, NULL, NULL, 14, 0, ADCx}, /* D33/PB14 */
+ {GPIOB, NULL, NULL, 15, 0, ADCx}, /* D34/PB15 */
+ {GPIOC, NULL, NULL, 6, 0, ADCx}, /* D35/PC6 */
+ {GPIOC, NULL, NULL, 7, 0, ADCx}, /* D36/PC7 */
+ {GPIOC, NULL, NULL, 8, 0, ADCx}, /* D37/PC8 */
+ {GPIOC, NULL, NULL, 9, 0, ADCx} /* D38/PC9 (BUT) */
};
#endif
diff --git a/wirish/boards/maple_RET6.cpp b/wirish/boards/maple_RET6.cpp
index ae31ce3..962affc 100644
--- a/wirish/boards/maple_RET6.cpp
+++ b/wirish/boards/maple_RET6.cpp
@@ -38,51 +38,54 @@ void boardInit(void) {
}
stm32_pin_info PIN_MAP[NR_GPIO_PINS] = {
- {GPIOA, TIMER2, 3, 4, 3}, /* D0/PA3 */
- {GPIOA, TIMER2, 2, 3, 2}, /* D1/PA2 */
- {GPIOA, TIMER2, 0, 1, 0}, /* D2/PA0 */
- {GPIOA, TIMER2, 1, 2, 1}, /* D3/PA1 */
- {GPIOB, NULL, 5, 0, ADCx}, /* D4/PB5 */
- {GPIOB, TIMER4, 6, 1, ADCx}, /* D5/PB6 */
- {GPIOA, TIMER1, 8, 1, ADCx}, /* D6/PA8 */
- {GPIOA, TIMER1, 9, 2, ADCx}, /* D7/PA9 */
- {GPIOA, TIMER1, 10, 3, ADCx}, /* D8/PA10 */
- {GPIOB, TIMER4, 7, 2, ADCx}, /* D9/PB7 */
- {GPIOA, NULL, 4, 0, 4}, /* D10/PA4 */
- {GPIOA, TIMER3, 7, 2, 7}, /* D11/PA7 */
- {GPIOA, TIMER3, 6, 1, 6}, /* D12/PA6 */
- {GPIOA, NULL, 5, 0, 5}, /* D13/PA5 (LED) */
- {GPIOB, TIMER4, 8, 3, ADCx}, /* D14/PB8 */
+
+ /* Top header */
+
+ {GPIOA, TIMER2, ADC1, 3, 4, 3}, /* D0/PA3 */
+ {GPIOA, TIMER2, ADC1, 2, 3, 2}, /* D1/PA2 */
+ {GPIOA, TIMER2, ADC1, 0, 1, 0}, /* D2/PA0 */
+ {GPIOA, TIMER2, ADC1, 1, 2, 1}, /* D3/PA1 */
+ {GPIOB, NULL, NULL, 5, 0, ADCx}, /* D4/PB5 */
+ {GPIOB, TIMER4, NULL, 6, 1, ADCx}, /* D5/PB6 */
+ {GPIOA, TIMER1, NULL, 8, 1, ADCx}, /* D6/PA8 */
+ {GPIOA, TIMER1, NULL, 9, 2, ADCx}, /* D7/PA9 */
+ {GPIOA, TIMER1, NULL, 10, 3, ADCx}, /* D8/PA10 */
+ {GPIOB, TIMER4, NULL, 7, 2, ADCx}, /* D9/PB7 */
+ {GPIOA, NULL, ADC1, 4, 0, 4}, /* D10/PA4 */
+ {GPIOA, TIMER3, ADC1, 7, 2, 7}, /* D11/PA7 */
+ {GPIOA, TIMER3, ADC1, 6, 1, 6}, /* D12/PA6 */
+ {GPIOA, NULL, ADC1, 5, 0, 5}, /* D13/PA5 (LED) */
+ {GPIOB, TIMER4, NULL, 8, 3, ADCx}, /* D14/PB8 */
/* Little header */
- {GPIOC, NULL, 0, 0, 10}, /* D15/PC0 */
- {GPIOC, NULL, 1, 0, 11}, /* D16/PC1 */
- {GPIOC, NULL, 2, 0, 12}, /* D17/PC2 */
- {GPIOC, NULL, 3, 0, 13}, /* D18/PC3 */
- {GPIOC, NULL, 4, 0, 14}, /* D19/PC4 */
- {GPIOC, NULL, 5, 0, 15}, /* D20/PC5 */
+ {GPIOC, NULL, ADC1, 0, 0, 10}, /* D15/PC0 */
+ {GPIOC, NULL, ADC1, 1, 0, 11}, /* D16/PC1 */
+ {GPIOC, NULL, ADC1, 2, 0, 12}, /* D17/PC2 */
+ {GPIOC, NULL, ADC1, 3, 0, 13}, /* D18/PC3 */
+ {GPIOC, NULL, ADC1, 4, 0, 14}, /* D19/PC4 */
+ {GPIOC, NULL, ADC1, 5, 0, 15}, /* D20/PC5 */
/* External header */
- {GPIOC, NULL, 13, 0, ADCx}, /* D21/PC13 */
- {GPIOC, NULL, 14, 0, ADCx}, /* D22/PC14 */
- {GPIOC, NULL, 15, 0, ADCx}, /* D23/PC15 */
- {GPIOB, TIMER4, 9, 4, ADCx}, /* D24/PB9 */
- {GPIOD, NULL, 2, 0, ADCx}, /* D25/PD2 */
- {GPIOC, NULL, 10, 0, ADCx}, /* D26/PC10 */
- {GPIOB, TIMER3, 0, 3, 8}, /* D27/PB0 */
- {GPIOB, TIMER3, 1, 4, 9}, /* D28/PB1 */
- {GPIOB, NULL, 10, 0, ADCx}, /* D29/PB10 */
- {GPIOB, NULL, 11, 0, ADCx}, /* D30/PB11 */
- {GPIOB, NULL, 12, 0, ADCx}, /* D31/PB12 */
- {GPIOB, NULL, 13, 0, ADCx}, /* D32/PB13 */
- {GPIOB, NULL, 14, 0, ADCx}, /* D33/PB14 */
- {GPIOB, NULL, 15, 0, ADCx}, /* D34/PB15 */
- {GPIOC, TIMER8, 6, 1, ADCx}, /* D35/PC6 */
- {GPIOC, TIMER8, 7, 2, ADCx}, /* D36/PC7 */
- {GPIOC, TIMER8, 8, 3, ADCx}, /* D37/PC8 */
- {GPIOC, TIMER8, 9, 4, ADCx} /* D38/PC9 (BUT) */
+ {GPIOC, NULL, NULL, 13, 0, ADCx}, /* D21/PC13 */
+ {GPIOC, NULL, NULL, 14, 0, ADCx}, /* D22/PC14 */
+ {GPIOC, NULL, NULL, 15, 0, ADCx}, /* D23/PC15 */
+ {GPIOB, TIMER4, NULL, 9, 4, ADCx}, /* D24/PB9 */
+ {GPIOD, NULL, NULL, 2, 0, ADCx}, /* D25/PD2 */
+ {GPIOC, NULL, NULL, 10, 0, ADCx}, /* D26/PC10 */
+ {GPIOB, TIMER3, ADC1, 0, 3, 8}, /* D27/PB0 */
+ {GPIOB, TIMER3, ADC1, 1, 4, 9}, /* D28/PB1 */
+ {GPIOB, NULL, NULL, 10, 0, ADCx}, /* D29/PB10 */
+ {GPIOB, NULL, NULL, 11, 0, ADCx}, /* D30/PB11 */
+ {GPIOB, NULL, NULL, 12, 0, ADCx}, /* D31/PB12 */
+ {GPIOB, NULL, NULL, 13, 0, ADCx}, /* D32/PB13 */
+ {GPIOB, NULL, NULL, 14, 0, ADCx}, /* D33/PB14 */
+ {GPIOB, NULL, NULL, 15, 0, ADCx}, /* D34/PB15 */
+ {GPIOC, TIMER8, NULL, 6, 1, ADCx}, /* D35/PC6 */
+ {GPIOC, TIMER8, NULL, 7, 2, ADCx}, /* D36/PC7 */
+ {GPIOC, TIMER8, NULL, 8, 3, ADCx}, /* D37/PC8 */
+ {GPIOC, TIMER8, NULL, 9, 4, ADCx} /* D38/PC9 (BUT) */
};
#endif
diff --git a/wirish/boards/maple_mini.cpp b/wirish/boards/maple_mini.cpp
index 8c005cf..66a0997 100644
--- a/wirish/boards/maple_mini.cpp
+++ b/wirish/boards/maple_mini.cpp
@@ -45,43 +45,43 @@ stm32_pin_info PIN_MAP[NR_GPIO_PINS] = {
/* Top header */
- {GPIOB, NULL, 11, 0, ADCx}, /* D0/PB11 */
- {GPIOB, NULL, 10, 0, ADCx}, /* D1/PB10 */
- {GPIOB, NULL, 2, 0, ADCx}, /* D2/PB2 */
- {GPIOB, TIMER3, 0, 3, 8}, /* D3/PB0 */
- {GPIOA, TIMER3, 7, 2, 7}, /* D4/PA7 */
- {GPIOA, TIMER3, 6, 1, 6}, /* D5/PA6 */
- {GPIOA, NULL, 5, 0, 5}, /* D6/PA5 */
- {GPIOA, NULL, 4, 0, 4}, /* D7/PA4 */
- {GPIOA, TIMER2, 3, 4, 3}, /* D8/PA3 */
- {GPIOA, TIMER2, 2, 3, 2}, /* D9/PA2 */
- {GPIOA, TIMER2, 1, 2, 1}, /* D10/PA1 */
- {GPIOA, TIMER2, 0, 1, 0}, /* D11/PA0 */
- {GPIOC, NULL, 15, 0, ADCx}, /* D12/PC15 */
- {GPIOC, NULL, 14, 0, ADCx}, /* D13/PC14 */
- {GPIOC, NULL, 13, 0, ADCx}, /* D14/PC13 */
+ {GPIOB, NULL, NULL, 11, 0, ADCx}, /* D0/PB11 */
+ {GPIOB, NULL, NULL, 10, 0, ADCx}, /* D1/PB10 */
+ {GPIOB, NULL, NULL, 2, 0, ADCx}, /* D2/PB2 */
+ {GPIOB, TIMER3, ADC1, 0, 3, 8}, /* D3/PB0 */
+ {GPIOA, TIMER3, ADC1, 7, 2, 7}, /* D4/PA7 */
+ {GPIOA, TIMER3, ADC1, 6, 1, 6}, /* D5/PA6 */
+ {GPIOA, NULL, ADC1, 5, 0, 5}, /* D6/PA5 */
+ {GPIOA, NULL, ADC1, 4, 0, 4}, /* D7/PA4 */
+ {GPIOA, TIMER2, ADC1, 3, 4, 3}, /* D8/PA3 */
+ {GPIOA, TIMER2, ADC1, 2, 3, 2}, /* D9/PA2 */
+ {GPIOA, TIMER2, ADC1, 1, 2, 1}, /* D10/PA1 */
+ {GPIOA, TIMER2, ADC1, 0, 1, 0}, /* D11/PA0 */
+ {GPIOC, NULL, NULL, 15, 0, ADCx}, /* D12/PC15 */
+ {GPIOC, NULL, NULL, 14, 0, ADCx}, /* D13/PC14 */
+ {GPIOC, NULL, NULL, 13, 0, ADCx}, /* D14/PC13 */
/* Bottom header */
- {GPIOB, TIMER4, 7, 2, ADCx}, /* D15/PB7 */
- {GPIOB, TIMER4, 6, 1, ADCx}, /* D16/PB6 */
- {GPIOB, NULL, 5, 0, ADCx}, /* D17/PB5 */
- {GPIOB, NULL, 4, 0, ADCx}, /* D18/PB4 */
- {GPIOB, NULL, 3, 0, ADCx}, /* D19/PB3 */
- {GPIOA, NULL, 15, 0, ADCx}, /* D20/PA15 */
- {GPIOA, NULL, 14, 0, ADCx}, /* D21/PA14 */
- {GPIOA, NULL, 13, 0, ADCx}, /* D22/PA13 */
- {GPIOA, NULL, 12, 0, ADCx}, /* D23/PA12 */
- {GPIOA, TIMER1, 11, 4, ADCx}, /* D24/PA11 */
- {GPIOA, TIMER1, 10, 3, ADCx}, /* D25/PA10 */
- {GPIOA, TIMER2, 9, 2, ADCx}, /* D26/PA9 */
- {GPIOA, TIMER1, 8, 1, ADCx}, /* D27/PA8 */
- {GPIOB, NULL, 15, 0, ADCx}, /* D28/PB15 */
- {GPIOB, NULL, 14, 0, ADCx}, /* D29/PB14 */
- {GPIOB, NULL, 13, 0, ADCx}, /* D30/PB13 */
- {GPIOB, NULL, 12, 0, ADCx}, /* D31/PB12 */
- {GPIOB, TIMER4, 8, 3, ADCx}, /* D32/PB8 */
- {GPIOB, TIMER3, 1, 4, 9}, /* D33/PB1 */
+ {GPIOB, TIMER4, NULL, 7, 2, ADCx}, /* D15/PB7 */
+ {GPIOB, TIMER4, NULL, 6, 1, ADCx}, /* D16/PB6 */
+ {GPIOB, NULL, NULL, 5, 0, ADCx}, /* D17/PB5 */
+ {GPIOB, NULL, NULL, 4, 0, ADCx}, /* D18/PB4 */
+ {GPIOB, NULL, NULL, 3, 0, ADCx}, /* D19/PB3 */
+ {GPIOA, NULL, NULL, 15, 0, ADCx}, /* D20/PA15 */
+ {GPIOA, NULL, NULL, 14, 0, ADCx}, /* D21/PA14 */
+ {GPIOA, NULL, NULL, 13, 0, ADCx}, /* D22/PA13 */
+ {GPIOA, NULL, NULL, 12, 0, ADCx}, /* D23/PA12 */
+ {GPIOA, TIMER1, NULL, 11, 4, ADCx}, /* D24/PA11 */
+ {GPIOA, TIMER1, NULL, 10, 3, ADCx}, /* D25/PA10 */
+ {GPIOA, TIMER2, NULL, 9, 2, ADCx}, /* D26/PA9 */
+ {GPIOA, TIMER1, NULL, 8, 1, ADCx}, /* D27/PA8 */
+ {GPIOB, NULL, NULL, 15, 0, ADCx}, /* D28/PB15 */
+ {GPIOB, NULL, NULL, 14, 0, ADCx}, /* D29/PB14 */
+ {GPIOB, NULL, NULL, 13, 0, ADCx}, /* D30/PB13 */
+ {GPIOB, NULL, NULL, 12, 0, ADCx}, /* D31/PB12 */
+ {GPIOB, TIMER4, NULL, 8, 3, ADCx}, /* D32/PB8 */
+ {GPIOB, TIMER3, ADC1, 1, 4, 9}, /* D33/PB1 */
};
#endif
diff --git a/wirish/boards/maple_native.cpp b/wirish/boards/maple_native.cpp
index c04e98f..75c6a2d 100644
--- a/wirish/boards/maple_native.cpp
+++ b/wirish/boards/maple_native.cpp
@@ -43,113 +43,113 @@ stm32_pin_info PIN_MAP[NR_GPIO_PINS] = {
/* Top header */
- {GPIOB, NULL, 10, 0, ADCx}, /* D0/PB10 */
- {GPIOB, NULL, 2, 0, ADCx}, /* D1/PB2 */
- {GPIOB, NULL, 12, 0, ADCx}, /* D2/PB12 */
- {GPIOB, NULL, 13, 0, ADCx}, /* D3/PB13 */
- {GPIOB, NULL, 14, 0, ADCx}, /* D4/PB14 */
- {GPIOB, NULL, 15, 0, ADCx}, /* D5/PB15 */
- {GPIOC, NULL, 0, 0, 10}, /* D6/PC0 */
- {GPIOC, NULL, 1, 0, 11}, /* D7/PC1 */
- {GPIOC, NULL, 2, 0, 12}, /* D8/PC2 */
- {GPIOC, NULL, 3, 0, 13}, /* D9/PC3 */
- {GPIOC, NULL, 4, 0, 14}, /* D10/PC4 */
- {GPIOC, NULL, 5, 0, 15}, /* D11/PC5 */
- {GPIOC, TIMER8, 6, 1, ADCx}, /* D12/PC6 */
- {GPIOC, TIMER8, 7, 2, ADCx}, /* D13/PC7 */
- {GPIOC, TIMER8, 8, 3, ADCx}, /* D14/PC8 */
- {GPIOC, TIMER8, 9, 4, ADCx}, /* D15/PC9 */
- {GPIOC, NULL, 10, 0, ADCx}, /* D16/PC10 */
- {GPIOC, NULL, 11, 0, ADCx}, /* D17/PC11 */
- {GPIOC, NULL, 12, 0, ADCx}, /* D18/PC12 */
- {GPIOC, NULL, 13, 0, ADCx}, /* D19/PC13 */
- {GPIOC, NULL, 14, 0, ADCx}, /* D20/PC14 */
- {GPIOC, NULL, 15, 0, ADCx}, /* D21/PC15 */
- {GPIOA, TIMER1, 8, 1, ADCx}, /* D22/PA8 */
- {GPIOA, TIMER1, 9, 2, ADCx}, /* D23/PA9 */
- {GPIOA, TIMER1, 10, 3, ADCx}, /* D24/PA10 */
- {GPIOB, TIMER4, 9, 4, ADCx}, /* D25/PB9 */
+ {GPIOB, NULL, NULL, 10, 0, ADCx}, /* D0/PB10 */
+ {GPIOB, NULL, NULL, 2, 0, ADCx}, /* D1/PB2 */
+ {GPIOB, NULL, NULL, 12, 0, ADCx}, /* D2/PB12 */
+ {GPIOB, NULL, NULL, 13, 0, ADCx}, /* D3/PB13 */
+ {GPIOB, NULL, NULL, 14, 0, ADCx}, /* D4/PB14 */
+ {GPIOB, NULL, NULL, 15, 0, ADCx}, /* D5/PB15 */
+ {GPIOC, NULL, ADC1, 0, 0, 10}, /* D6/PC0 */
+ {GPIOC, NULL, ADC1, 1, 0, 11}, /* D7/PC1 */
+ {GPIOC, NULL, ADC1, 2, 0, 12}, /* D8/PC2 */
+ {GPIOC, NULL, ADC1, 3, 0, 13}, /* D9/PC3 */
+ {GPIOC, NULL, ADC1, 4, 0, 14}, /* D10/PC4 */
+ {GPIOC, NULL, ADC1, 5, 0, 15}, /* D11/PC5 */
+ {GPIOC, TIMER8, NULL, 6, 1, ADCx}, /* D12/PC6 */
+ {GPIOC, TIMER8, NULL, 7, 2, ADCx}, /* D13/PC7 */
+ {GPIOC, TIMER8, NULL, 8, 3, ADCx}, /* D14/PC8 */
+ {GPIOC, TIMER8, NULL, 9, 4, ADCx}, /* D15/PC9 */
+ {GPIOC, NULL, NULL, 10, 0, ADCx}, /* D16/PC10 */
+ {GPIOC, NULL, NULL, 11, 0, ADCx}, /* D17/PC11 */
+ {GPIOC, NULL, NULL, 12, 0, ADCx}, /* D18/PC12 */
+ {GPIOC, NULL, NULL, 13, 0, ADCx}, /* D19/PC13 */
+ {GPIOC, NULL, NULL, 14, 0, ADCx}, /* D20/PC14 */
+ {GPIOC, NULL, NULL, 15, 0, ADCx}, /* D21/PC15 */
+ {GPIOA, TIMER1, NULL, 8, 1, ADCx}, /* D22/PA8 */
+ {GPIOA, TIMER1, NULL, 9, 2, ADCx}, /* D23/PA9 */
+ {GPIOA, TIMER1, NULL, 10, 3, ADCx}, /* D24/PA10 */
+ {GPIOB, TIMER4, NULL, 9, 4, ADCx}, /* D25/PB9 */
/* Bottom header */
- /* FIXME (?) What about D48--D50 also being TIMER2_CH[234]? */
+ /* Note: D{48, 49, 50} are also TIMER2_CH{2, 3, 4}, respectively. */
- {GPIOD, NULL, 2, 0, ADCx}, /* D26/PD2 */
- {GPIOD, NULL, 3, 0, ADCx}, /* D27/PD3 */
- {GPIOD, NULL, 6, 0, ADCx}, /* D28/PD6 */
- {GPIOG, NULL, 11, 0, ADCx}, /* D29/PG11 */
- {GPIOG, NULL, 12, 0, ADCx}, /* D30/PG12 */
- {GPIOG, NULL, 13, 0, ADCx}, /* D31/PG13 */
- {GPIOG, NULL, 14, 0, ADCx}, /* D32/PG14 */
- {GPIOG, NULL, 8, 0, ADCx}, /* D33/PG8 */
- {GPIOG, NULL, 7, 0, ADCx}, /* D34/PG7 */
- {GPIOG, NULL, 6, 0, ADCx}, /* D35/PG6 */
- {GPIOB, NULL, 5, 0, ADCx}, /* D36/PB5 */
- {GPIOB, TIMER4, 6, 1, ADCx}, /* D37/PB6 */
- {GPIOB, TIMER4, 7, 2, ADCx}, /* D38/PB7 */
- {GPIOF, NULL, 6, 0, 4}, /* D39/PF6 */
- {GPIOF, NULL, 7, 0, 5}, /* D40/PF7 */
- {GPIOF, NULL, 8, 0, 6}, /* D41/PF8 */
- {GPIOF, NULL, 9, 0, 7}, /* D42/PF9 */
- {GPIOF, NULL, 10, 0, 8}, /* D43/PF10 */
- {GPIOF, NULL, 11, 0, ADCx}, /* D44/PF11 */
- {GPIOB, TIMER3, 1, 4, 9}, /* D45/PB1 */
- {GPIOB, TIMER3, 0, 3, 8}, /* D46/PB0 */
- {GPIOA, TIMER5, 0, 1, 0}, /* D47/PA0 */
- {GPIOA, TIMER5, 1, 2, 1}, /* D48/PA1 */
- {GPIOA, TIMER5, 2, 3, 2}, /* D49/PA2 */
- {GPIOA, TIMER5, 3, 4, 3}, /* D50/PA3 */
- {GPIOA, NULL, 4, 0, 4}, /* D51/PA4 */
- {GPIOA, NULL, 5, 0, 5}, /* D52/PA5 */
- {GPIOA, TIMER3, 6, 1, 6}, /* D53/PA6 */
- {GPIOA, TIMER3, 7, 2, 7}, /* D54/PA7 */
+ {GPIOD, NULL, NULL, 2, 0, ADCx}, /* D26/PD2 */
+ {GPIOD, NULL, NULL, 3, 0, ADCx}, /* D27/PD3 */
+ {GPIOD, NULL, NULL, 6, 0, ADCx}, /* D28/PD6 */
+ {GPIOG, NULL, NULL, 11, 0, ADCx}, /* D29/PG11 */
+ {GPIOG, NULL, NULL, 12, 0, ADCx}, /* D30/PG12 */
+ {GPIOG, NULL, NULL, 13, 0, ADCx}, /* D31/PG13 */
+ {GPIOG, NULL, NULL, 14, 0, ADCx}, /* D32/PG14 */
+ {GPIOG, NULL, NULL, 8, 0, ADCx}, /* D33/PG8 */
+ {GPIOG, NULL, NULL, 7, 0, ADCx}, /* D34/PG7 */
+ {GPIOG, NULL, NULL, 6, 0, ADCx}, /* D35/PG6 */
+ {GPIOB, NULL, NULL, 5, 0, ADCx}, /* D36/PB5 */
+ {GPIOB, TIMER4, NULL, 6, 1, ADCx}, /* D37/PB6 */
+ {GPIOB, TIMER4, NULL, 7, 2, ADCx}, /* D38/PB7 */
+ {GPIOF, NULL, ADC3, 6, 0, 4}, /* D39/PF6 */
+ {GPIOF, NULL, ADC3, 7, 0, 5}, /* D40/PF7 */
+ {GPIOF, NULL, ADC3, 8, 0, 6}, /* D41/PF8 */
+ {GPIOF, NULL, ADC3, 9, 0, 7}, /* D42/PF9 */
+ {GPIOF, NULL, ADC3, 10, 0, 8}, /* D43/PF10 */
+ {GPIOF, NULL, NULL, 11, 0, ADCx}, /* D44/PF11 */
+ {GPIOB, TIMER3, ADC1, 1, 4, 9}, /* D45/PB1 */
+ {GPIOB, TIMER3, ADC1, 0, 3, 8}, /* D46/PB0 */
+ {GPIOA, TIMER5, ADC1, 0, 1, 0}, /* D47/PA0 */
+ {GPIOA, TIMER5, ADC1, 1, 2, 1}, /* D48/PA1 */
+ {GPIOA, TIMER5, ADC1, 2, 3, 2}, /* D49/PA2 */
+ {GPIOA, TIMER5, ADC1, 3, 4, 3}, /* D50/PA3 */
+ {GPIOA, NULL, ADC1, 4, 0, 4}, /* D51/PA4 */
+ {GPIOA, NULL, ADC1, 5, 0, 5}, /* D52/PA5 */
+ {GPIOA, TIMER3, ADC1, 6, 1, 6}, /* D53/PA6 */
+ {GPIOA, TIMER3, ADC1, 7, 2, 7}, /* D54/PA7 */
/* Right (triple) header */
- {GPIOF, NULL, 0, 0, ADCx}, /* D55/PF0 */
- {GPIOD, NULL, 11, 0, ADCx}, /* D56/PD11 */
- {GPIOD, NULL, 14, 0, ADCx}, /* D57/PD14 */
- {GPIOF, NULL, 1, 0, ADCx}, /* D58/PF1 */
- {GPIOD, NULL, 12, 0, ADCx}, /* D59/PD12 */
- {GPIOD, NULL, 15, 0, ADCx}, /* D60/PD15 */
- {GPIOF, NULL, 2, 0, ADCx}, /* D61/PF2 */
- {GPIOD, NULL, 13, 0, ADCx}, /* D62/PD13 */
- {GPIOD, NULL, 0, 0, ADCx}, /* D63/PD0 */
- {GPIOF, NULL, 3, 0, ADCx}, /* D64/PF3 */
- {GPIOE, NULL, 3, 0, ADCx}, /* D65/PE3 */
- {GPIOD, NULL, 1, 0, ADCx}, /* D66/PD1 */
- {GPIOF, NULL, 4, 0, ADCx}, /* D67/PF4 */
- {GPIOE, NULL, 4, 0, ADCx}, /* D68/PE4 */
- {GPIOE, NULL, 7, 0, ADCx}, /* D69/PE7 */
- {GPIOF, NULL, 5, 0, ADCx}, /* D70/PF5 */
- {GPIOE, NULL, 5, 0, ADCx}, /* D71/PE5 */
- {GPIOE, NULL, 8, 0, ADCx}, /* D72/PE8 */
- {GPIOF, NULL, 12, 0, ADCx}, /* D73/PF12 */
- {GPIOE, NULL, 6, 0, ADCx}, /* D74/PE6 */
- {GPIOE, NULL, 9, 0, ADCx}, /* D75/PE9 */
- {GPIOF, NULL, 13, 0, ADCx}, /* D76/PF13 */
- {GPIOE, NULL, 10, 0, ADCx}, /* D77/PE10 */
- {GPIOF, NULL, 14, 0, ADCx}, /* D78/PF14 */
- {GPIOG, NULL, 9, 0, ADCx}, /* D79/PG9 */
- {GPIOE, NULL, 11, 0, ADCx}, /* D80/PE11 */
- {GPIOF, NULL, 15, 0, ADCx}, /* D81/PF15 */
- {GPIOG, NULL, 10, 0, ADCx}, /* D82/PG10 */
- {GPIOE, NULL, 12, 0, ADCx}, /* D83/PE12 */
- {GPIOG, NULL, 0, 0, ADCx}, /* D84/PG0 */
- {GPIOD, NULL, 5, 0, ADCx}, /* D85/PD5 */
- {GPIOE, NULL, 13, 0, ADCx}, /* D86/PE13 */
- {GPIOG, NULL, 1, 0, ADCx}, /* D87/PG1 */
- {GPIOD, NULL, 4, 0, ADCx}, /* D88/PD4 */
- {GPIOE, NULL, 14, 0, ADCx}, /* D89/PE14 */
- {GPIOG, NULL, 2, 0, ADCx}, /* D90/PG2 */
- {GPIOE, NULL, 1, 0, ADCx}, /* D91/PE1 */
- {GPIOE, NULL, 15, 0, ADCx}, /* D92/PE15 */
- {GPIOG, NULL, 3, 0, ADCx}, /* D93/PG3 */
- {GPIOE, NULL, 0, 0, ADCx}, /* D94/PE0 */
- {GPIOD, NULL, 8, 0, ADCx}, /* D95/PD8 */
- {GPIOG, NULL, 4, 0, ADCx}, /* D96/PG4 */
- {GPIOD, NULL, 9, 0, ADCx}, /* D97/PD9 */
- {GPIOG, NULL, 5, 0, ADCx}, /* D98/PG5 */
- {GPIOD, NULL, 10, 0, ADCx} /* D99/PD10 */
+ {GPIOF, NULL, NULL, 0, 0, ADCx}, /* D55/PF0 */
+ {GPIOD, NULL, NULL, 11, 0, ADCx}, /* D56/PD11 */
+ {GPIOD, NULL, NULL, 14, 0, ADCx}, /* D57/PD14 */
+ {GPIOF, NULL, NULL, 1, 0, ADCx}, /* D58/PF1 */
+ {GPIOD, NULL, NULL, 12, 0, ADCx}, /* D59/PD12 */
+ {GPIOD, NULL, NULL, 15, 0, ADCx}, /* D60/PD15 */
+ {GPIOF, NULL, NULL, 2, 0, ADCx}, /* D61/PF2 */
+ {GPIOD, NULL, NULL, 13, 0, ADCx}, /* D62/PD13 */
+ {GPIOD, NULL, NULL, 0, 0, ADCx}, /* D63/PD0 */
+ {GPIOF, NULL, NULL, 3, 0, ADCx}, /* D64/PF3 */
+ {GPIOE, NULL, NULL, 3, 0, ADCx}, /* D65/PE3 */
+ {GPIOD, NULL, NULL, 1, 0, ADCx}, /* D66/PD1 */
+ {GPIOF, NULL, NULL, 4, 0, ADCx}, /* D67/PF4 */
+ {GPIOE, NULL, NULL, 4, 0, ADCx}, /* D68/PE4 */
+ {GPIOE, NULL, NULL, 7, 0, ADCx}, /* D69/PE7 */
+ {GPIOF, NULL, NULL, 5, 0, ADCx}, /* D70/PF5 */
+ {GPIOE, NULL, NULL, 5, 0, ADCx}, /* D71/PE5 */
+ {GPIOE, NULL, NULL, 8, 0, ADCx}, /* D72/PE8 */
+ {GPIOF, NULL, NULL, 12, 0, ADCx}, /* D73/PF12 */
+ {GPIOE, NULL, NULL, 6, 0, ADCx}, /* D74/PE6 */
+ {GPIOE, NULL, NULL, 9, 0, ADCx}, /* D75/PE9 */
+ {GPIOF, NULL, NULL, 13, 0, ADCx}, /* D76/PF13 */
+ {GPIOE, NULL, NULL, 10, 0, ADCx}, /* D77/PE10 */
+ {GPIOF, NULL, NULL, 14, 0, ADCx}, /* D78/PF14 */
+ {GPIOG, NULL, NULL, 9, 0, ADCx}, /* D79/PG9 */
+ {GPIOE, NULL, NULL, 11, 0, ADCx}, /* D80/PE11 */
+ {GPIOF, NULL, NULL, 15, 0, ADCx}, /* D81/PF15 */
+ {GPIOG, NULL, NULL, 10, 0, ADCx}, /* D82/PG10 */
+ {GPIOE, NULL, NULL, 12, 0, ADCx}, /* D83/PE12 */
+ {GPIOG, NULL, NULL, 0, 0, ADCx}, /* D84/PG0 */
+ {GPIOD, NULL, NULL, 5, 0, ADCx}, /* D85/PD5 */
+ {GPIOE, NULL, NULL, 13, 0, ADCx}, /* D86/PE13 */
+ {GPIOG, NULL, NULL, 1, 0, ADCx}, /* D87/PG1 */
+ {GPIOD, NULL, NULL, 4, 0, ADCx}, /* D88/PD4 */
+ {GPIOE, NULL, NULL, 14, 0, ADCx}, /* D89/PE14 */
+ {GPIOG, NULL, NULL, 2, 0, ADCx}, /* D90/PG2 */
+ {GPIOE, NULL, NULL, 1, 0, ADCx}, /* D91/PE1 */
+ {GPIOE, NULL, NULL, 15, 0, ADCx}, /* D92/PE15 */
+ {GPIOG, NULL, NULL, 3, 0, ADCx}, /* D93/PG3 */
+ {GPIOE, NULL, NULL, 0, 0, ADCx}, /* D94/PE0 */
+ {GPIOD, NULL, NULL, 8, 0, ADCx}, /* D95/PD8 */
+ {GPIOG, NULL, NULL, 4, 0, ADCx}, /* D96/PG4 */
+ {GPIOD, NULL, NULL, 9, 0, ADCx}, /* D97/PD9 */
+ {GPIOG, NULL, NULL, 5, 0, ADCx}, /* D98/PG5 */
+ {GPIOD, NULL, NULL, 10, 0, ADCx} /* D99/PD10 */
};
#endif
diff --git a/wirish/ext_interrupts.cpp b/wirish/ext_interrupts.cpp
index 060994f..f9ccd39 100644
--- a/wirish/ext_interrupts.cpp
+++ b/wirish/ext_interrupts.cpp
@@ -49,7 +49,7 @@ void attachInterrupt(uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode) {
exti_trigger_mode outMode = exti_out_mode(mode);
- exti_attach_interrupt((afio_exti_num)(PIN_MAP[pin].gpio_pin),
+ exti_attach_interrupt((afio_exti_num)(PIN_MAP[pin].gpio_bit),
gpio_exti_port(PIN_MAP[pin].gpio_device),
handler,
outMode);
@@ -64,7 +64,7 @@ void detachInterrupt(uint8 pin) {
return;
}
- exti_detach_interrupt((afio_exti_num)(PIN_MAP[pin].gpio_pin));
+ exti_detach_interrupt((afio_exti_num)(PIN_MAP[pin].gpio_bit));
}
static inline exti_trigger_mode exti_out_mode(ExtIntTriggerMode mode) {
diff --git a/wirish/io.h b/wirish/io.h
index 8dad1d1..7d4fab1 100644
--- a/wirish/io.h
+++ b/wirish/io.h
@@ -28,8 +28,8 @@
* @brief Arduino-compatible digital pin I/O interface.
*/
-#ifndef _IO_H
-#define _IO_H
+#ifndef _IO_H_
+#define _IO_H_
#include "gpio.h"
#include "adc.h"
@@ -45,8 +45,8 @@
* This enum specifies the complete set of possible configurations;
* not every pin can have all of these modes. For example, on the
* Maple, pin 15 may be configured as INPUT_ANALOG, but not as PWM.
- * See your device's silkscreen and and the GPIO documentation for
- * more information.
+ * See your board's documentation and silkscreen for more information
+ * on what functionality is available on each pin.
*
* @see pinMode()
*/
@@ -114,8 +114,7 @@ typedef enum WiringPinMode {
/**
* Configure behavior of a GPIO pin.
*
- * @param pin Pin to configure. One of: 0-38 (pin numbers as labeled
- * on silkscreen), or D0-D38 (symbols for same)
+ * @param pin Number of pin to configure.
* @param mode Mode corresponding to desired pin behavior.
* @see WiringPinMode
*/
@@ -136,8 +135,7 @@ void digitalWrite(uint8 pin, uint8 value);
* Read a digital value from a pin. The pin must have its mode set to
* one of INPUT, INPUT_PULLUP, and INPUT_PULLDOWN.
*
- * @param pin Pin to read from. One of: 0-38 (pin numbers as labeled
- * on silkscreen), or D0-D38 (symbols for same)
+ * @param pin Pin to read from.
* @return LOW or HIGH.
* @see pinMode()
*/
@@ -146,18 +144,14 @@ uint32 digitalRead(uint8 pin);
/**
* Read an analog value from pin. This function blocks during ADC
* conversion, and has 12 bits of resolution. The pin must have its
- * mode set to INPUT_ANALOG. Ignoring function call overhead,
- * conversion time is 55.5 cycles.
+ * mode set to INPUT_ANALOG.
*
- * @param pin Pin to read from. One of: 0, 1, 2, 3, 10, 11, 12, 13,
- * 15, 16, 17, 18, 19, 20, 27, 28.
-
- * @return ADC-converted voltage, in the range 0--4095, inclusive
- * (i.e. a 12-bit ADC conversion).
-
+ * @param pin Pin to read from.
+ * @return Converted voltage, in the range 0--4095, (i.e. a 12-bit ADC
+ * conversion).
* @see pinMode()
*/
-uint32 analogRead(uint8 pin);
+uint16 analogRead(uint8 pin);
/**
* Toggles the digital value at the given pin.
@@ -207,14 +201,15 @@ uint8 isButtonPressed();
* pinMode(BOARD_BUTTON_PIN, INPUT).
*
* @param timeout_millis Number of milliseconds to wait until the
- * button is pressed. If timeout_millis is 0, wait forever.
+ * button is pressed. If timeout_millis is left out (or 0), wait
+ * forever.
*
* @return true, if the button was pressed; false, if the timeout was
* reached.
*
* @see pinMode()
*/
-uint8 waitForButtonPress(uint32 timeout_millis);
+uint8 waitForButtonPress(uint32 timeout_millis=0);
/**
* Shift out a byte of data, one bit at a time.
diff --git a/wirish/pwm.cpp b/wirish/pwm.cpp
index 6b09cef..4c803d2 100644
--- a/wirish/pwm.cpp
+++ b/wirish/pwm.cpp
@@ -38,5 +38,5 @@ void pwmWrite(uint8 pin, uint16 duty_cycle) {
return;
}
- timer_set_compare(dev, PIN_MAP[pin].timer_chan, duty_cycle);
+ timer_set_compare(dev, PIN_MAP[pin].timer_channel, duty_cycle);
}
diff --git a/wirish/rules.mk b/wirish/rules.mk
index c1d59bc..7715068 100644
--- a/wirish/rules.mk
+++ b/wirish/rules.mk
@@ -16,6 +16,7 @@ cSRCS_$(d) :=
cppSRCS_$(d) := wirish_math.cpp \
Print.cpp \
+ boards.cpp \
boards/maple.cpp \
boards/maple_mini.cpp \
boards/maple_native.cpp \
@@ -24,14 +25,13 @@ cppSRCS_$(d) := wirish_math.cpp \
comm/HardwareSPI.cpp \
usb_serial.cpp \
cxxabi-compat.cpp \
- wirish.cpp \
wirish_shift.cpp \
wirish_analog.cpp \
time.cpp \
pwm.cpp \
ext_interrupts.cpp \
wirish_digital.cpp \
- native_sram.cpp \
+ native_sram.cpp
cFILES_$(d) := $(cSRCS_$(d):%=$(d)/%)
cppFILES_$(d) := $(cppSRCS_$(d):%=$(d)/%)
diff --git a/wirish/wirish.h b/wirish/wirish.h
index 13b14b6..880157d 100644
--- a/wirish/wirish.h
+++ b/wirish/wirish.h
@@ -67,7 +67,5 @@
typedef uint8 boolean;
typedef uint8 byte;
-void init(void);
-
#endif
diff --git a/wirish/wirish_analog.cpp b/wirish/wirish_analog.cpp
index 9e99aa5..8756caf 100644
--- a/wirish/wirish_analog.cpp
+++ b/wirish/wirish_analog.cpp
@@ -31,11 +31,12 @@
#include "io.h"
/* Assumes that the ADC has been initialized and that the pin is set
- * to ANALOG_INPUT */
-uint32 analogRead(uint8 pin) {
- if(PIN_MAP[pin].adc_channel == ADCx) {
+ * to INPUT_ANALOG */
+uint16 analogRead(uint8 pin) {
+ const adc_dev *dev = PIN_MAP[pin].adc_device;
+ if (dev == NULL) {
return 0;
}
- return adc_read(ADC1, PIN_MAP[pin].adc_channel);
+ return adc_read(dev, PIN_MAP[pin].adc_channel);
}
diff --git a/wirish/wirish_digital.cpp b/wirish/wirish_digital.cpp
index 278cf10..115e91e 100644
--- a/wirish/wirish_digital.cpp
+++ b/wirish/wirish_digital.cpp
@@ -70,20 +70,14 @@ void pinMode(uint8 pin, WiringPinMode mode) {
return;
}
- gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_pin, outputMode);
+ gpio_set_mode(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, outputMode);
if (PIN_MAP[pin].timer_device != NULL) {
- /* enable/disable timer channels if we're switching into or
- out of pwm */
- if (pwm) {
- timer_set_mode(PIN_MAP[pin].timer_device,
- PIN_MAP[pin].timer_chan,
- TIMER_PWM);
- } else {
- timer_set_mode(PIN_MAP[pin].timer_device,
- PIN_MAP[pin].timer_chan,
- TIMER_DISABLED);
- }
+ /* Enable/disable timer channels if we're switching into or
+ * out of PWM. */
+ timer_set_mode(PIN_MAP[pin].timer_device,
+ PIN_MAP[pin].timer_channel,
+ pwm ? TIMER_PWM : TIMER_DISABLED);
}
}
@@ -93,7 +87,7 @@ uint32 digitalRead(uint8 pin) {
return 0;
}
- return gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_pin) ?
+ return gpio_read_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit) ?
HIGH : LOW;
}
@@ -102,7 +96,7 @@ void digitalWrite(uint8 pin, uint8 val) {
return;
}
- gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_pin, val);
+ gpio_write_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit, val);
}
void togglePin(uint8 pin) {
@@ -110,12 +104,14 @@ void togglePin(uint8 pin) {
return;
}
- gpio_toggle_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_pin);
+ gpio_toggle_bit(PIN_MAP[pin].gpio_device, PIN_MAP[pin].gpio_bit);
}
+#define BUTTON_DEBOUNCE_DELAY 10
+
uint8 isButtonPressed() {
if (digitalRead(BOARD_BUTTON_PIN)) {
- delay(1);
+ delay(BUTTON_DEBOUNCE_DELAY);
while (digitalRead(BOARD_BUTTON_PIN))
;
return true;
diff --git a/wirish/wirish_types.h b/wirish/wirish_types.h
index 84591ea..7d6e31a 100644
--- a/wirish/wirish_types.h
+++ b/wirish/wirish_types.h
@@ -32,20 +32,28 @@
#include "gpio.h"
#include "timer.h"
+#include "adc.h"
#ifndef _WIRISH_TYPES_H_
#define _WIRISH_TYPES_H_
-/** Stores STM32-specific information related to a given pin. */
+/**
+ * Invalid stm32_pin_info adc_channel value.
+ * @see stm32_pin_info
+ */
+#define ADCx 0xFF
+
+/**
+ * @brief Stores STM32-specific information related to a given Maple pin.
+ * @see PIN_MAP
+ */
typedef struct stm32_pin_info {
- gpio_dev *gpio_device; /**< Maple pin's GPIO device */
- timer_dev *timer_device; /**< Maple pin's timer device, or NULL if none. */
- uint8 gpio_pin; /**< GPIO pin */
- uint8 timer_chan; /**< Timer channel, or 0 if none. */
- uint8 adc_channel; /**< Pin ADC channel, or ADCx if none. */
+ gpio_dev *gpio_device; /**< Maple pin's GPIO device */
+ timer_dev *timer_device; /**< Pin's timer device, if any. */
+ const adc_dev *adc_device; /**< ADC device, if any. */
+ uint8 gpio_bit; /**< Pin's GPIO port bit. */
+ uint8 timer_channel; /**< Timer channel, or 0 if none. */
+ uint8 adc_channel; /**< Pin ADC channel, or ADCx if none. */
} stm32_pin_info;
-/** Invalid adc_channel value */
-#define ADCx 0xFF
-
#endif