From a8e9a985d50829cdffb6c20177eea0f206311f62 Mon Sep 17 00:00:00 2001 From: Ichiro Kuroki Date: Sat, 10 Apr 2021 13:38:44 +0300 Subject: [PATCH 1/3] boards/arduino-nano-33-iot: add PWM configuration --- boards/arduino-nano-33-iot/Kconfig | 1 + boards/arduino-nano-33-iot/Makefile.features | 1 + .../arduino-nano-33-iot/include/periph_conf.h | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/boards/arduino-nano-33-iot/Kconfig b/boards/arduino-nano-33-iot/Kconfig index a48a492cc9..b740f92b24 100644 --- a/boards/arduino-nano-33-iot/Kconfig +++ b/boards/arduino-nano-33-iot/Kconfig @@ -12,6 +12,7 @@ config BOARD_ARDUINO_NANO_33_IOT default y select CPU_MODEL_SAMD21G18A select HAS_PERIPH_I2C + select HAS_PERIPH_PWM select HAS_PERIPH_RTC select HAS_PERIPH_RTT select HAS_PERIPH_SPI diff --git a/boards/arduino-nano-33-iot/Makefile.features b/boards/arduino-nano-33-iot/Makefile.features index 6aae77d530..1912e23964 100644 --- a/boards/arduino-nano-33-iot/Makefile.features +++ b/boards/arduino-nano-33-iot/Makefile.features @@ -3,6 +3,7 @@ CPU_MODEL = samd21g18a # Put defined MCU peripherals here (in alphabetical order) FEATURES_PROVIDED += periph_i2c +FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc FEATURES_PROVIDED += periph_rtt FEATURES_PROVIDED += periph_spi diff --git a/boards/arduino-nano-33-iot/include/periph_conf.h b/boards/arduino-nano-33-iot/include/periph_conf.h index e05d2df77a..a09184d08a 100644 --- a/boards/arduino-nano-33-iot/include/periph_conf.h +++ b/boards/arduino-nano-33-iot/include/periph_conf.h @@ -139,6 +139,46 @@ static const uart_conf_t uart_config[] = { #define UART_NUMOF ARRAY_SIZE(uart_config) /** @} */ + +/** + * @name PWM configuration + * @{ + */ +#define PWM_0_EN 1 +#define PWM_1_EN 1 + +#if PWM_0_EN +/* PWM0 channels */ +static const pwm_conf_chan_t pwm_chan0_config[] = { + /* GPIO pin, MUX value, TCC channel */ + { GPIO_PIN(PA, 4), GPIO_MUX_E, 0}, + { GPIO_PIN(PA, 5), GPIO_MUX_E, 1}, +}; +#endif +#if PWM_1_EN +/* PWM1 channels */ +static const pwm_conf_chan_t pwm_chan1_config[] = { + /* GPIO pin, MUX value, TCC channel */ + { GPIO_PIN(PA, 10), GPIO_MUX_E, 0 }, + { GPIO_PIN(PA, 11), GPIO_MUX_E, 1 }, +}; +#endif + +/* PWM device configuration */ +static const pwm_conf_t pwm_config[] = { +#if PWM_0_EN + {TCC_CONFIG(TCC0), pwm_chan0_config, ARRAY_SIZE(pwm_chan0_config), SAM0_GCLK_MAIN}, +#endif + +#if PWM_1_EN + {TCC_CONFIG(TCC1), pwm_chan1_config, ARRAY_SIZE(pwm_chan1_config), SAM0_GCLK_MAIN}, +#endif +}; + +/* number of devices that are actually defined */ +#define PWM_NUMOF ARRAY_SIZE(pwm_config) +/** @} */ + /** * @name I2C configuration * @{ From 068f029cc8521c220fad35f1d51399de9d7fb20f Mon Sep 17 00:00:00 2001 From: Ichiro Kuroki Date: Sat, 10 Apr 2021 14:01:10 +0300 Subject: [PATCH 2/3] boards/arduino-nano-33-iot: add ADC configuration --- boards/arduino-nano-33-iot/Kconfig | 1 + boards/arduino-nano-33-iot/Makefile.features | 1 + .../arduino-nano-33-iot/include/periph_conf.h | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/boards/arduino-nano-33-iot/Kconfig b/boards/arduino-nano-33-iot/Kconfig index b740f92b24..99ca1a5c31 100644 --- a/boards/arduino-nano-33-iot/Kconfig +++ b/boards/arduino-nano-33-iot/Kconfig @@ -11,6 +11,7 @@ config BOARD_ARDUINO_NANO_33_IOT bool default y select CPU_MODEL_SAMD21G18A + select HAS_PERIPH_ADC select HAS_PERIPH_I2C select HAS_PERIPH_PWM select HAS_PERIPH_RTC diff --git a/boards/arduino-nano-33-iot/Makefile.features b/boards/arduino-nano-33-iot/Makefile.features index 1912e23964..c43f111ff1 100644 --- a/boards/arduino-nano-33-iot/Makefile.features +++ b/boards/arduino-nano-33-iot/Makefile.features @@ -2,6 +2,7 @@ CPU = samd21 CPU_MODEL = samd21g18a # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_i2c FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc diff --git a/boards/arduino-nano-33-iot/include/periph_conf.h b/boards/arduino-nano-33-iot/include/periph_conf.h index a09184d08a..7d8275c6af 100644 --- a/boards/arduino-nano-33-iot/include/periph_conf.h +++ b/boards/arduino-nano-33-iot/include/periph_conf.h @@ -179,6 +179,33 @@ static const pwm_conf_t pwm_config[] = { #define PWM_NUMOF ARRAY_SIZE(pwm_config) /** @} */ +/** + * @name ADC configuration + * @{ + */ + +/* ADC Default values */ +#define ADC_PRESCALER ADC_CTRLB_PRESCALER_DIV512 + +#define ADC_NEG_INPUT ADC_INPUTCTRL_MUXNEG_GND +#define ADC_GAIN_FACTOR_DEFAULT ADC_INPUTCTRL_GAIN_1X +#define ADC_REF_DEFAULT ADC_REFCTRL_REFSEL_INT1V + +static const adc_conf_chan_t adc_channels[] = { + /* port, pin, muxpos */ + {GPIO_PIN(PA, 2), ADC_INPUTCTRL_MUXPOS_PIN0}, /* A0 */ + {GPIO_PIN(PB, 2), ADC_INPUTCTRL_MUXPOS_PIN10}, /* A1 */ + {GPIO_PIN(PA, 11), ADC_INPUTCTRL_MUXPOS_PIN19}, /* A2 */ + {GPIO_PIN(PA, 10), ADC_INPUTCTRL_MUXPOS_PIN18}, /* A3 */ + {GPIO_PIN(PB, 8), ADC_INPUTCTRL_MUXPOS_PIN2}, /* A4 */ + {GPIO_PIN(PB, 9), ADC_INPUTCTRL_MUXPOS_PIN3}, /* A5 */ + {GPIO_PIN(PA, 9), ADC_INPUTCTRL_MUXPOS_PIN17}, /* A6 */ + {GPIO_PIN(PB, 3), ADC_INPUTCTRL_MUXPOS_PIN11}, /* A7 */ +}; + +#define ADC_NUMOF ARRAY_SIZE(adc_channels) +/** @} */ + /** * @name I2C configuration * @{ From 1cc02aef2f68eae8e1ab521499e890b6784da089 Mon Sep 17 00:00:00 2001 From: Ichiro Kuroki Date: Sat, 10 Apr 2021 14:07:47 +0300 Subject: [PATCH 3/3] boards/arduino-nano-33-iot: extend SPI configuration --- boards/arduino-nano-33-iot/include/periph_conf.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/boards/arduino-nano-33-iot/include/periph_conf.h b/boards/arduino-nano-33-iot/include/periph_conf.h index 7d8275c6af..b41bac9f73 100644 --- a/boards/arduino-nano-33-iot/include/periph_conf.h +++ b/boards/arduino-nano-33-iot/include/periph_conf.h @@ -139,7 +139,6 @@ static const uart_conf_t uart_config[] = { #define UART_NUMOF ARRAY_SIZE(uart_config) /** @} */ - /** * @name PWM configuration * @{ @@ -241,6 +240,18 @@ static const spi_conf_t spi_config[] = { .mosi_pad = SPI_PAD_MOSI_0_SCK_3, .gclk_src = SAM0_GCLK_MAIN, }, + { + .dev = &SERCOM3->SPI, + .miso_pin = GPIO_PIN(PA, 19), + .mosi_pin = GPIO_PIN(PA, 16), + .clk_pin = GPIO_PIN(PA, 17), + .miso_mux = GPIO_MUX_D, + .mosi_mux = GPIO_MUX_D, + .clk_mux = GPIO_MUX_D, + .miso_pad = SPI_PAD_MISO_3, + .mosi_pad = SPI_PAD_MOSI_0_SCK_1, + .gclk_src = SAM0_GCLK_MAIN, + }, }; #define SPI_NUMOF ARRAY_SIZE(spi_config)