diff --git a/cores/arduino/zephyrCommon.cpp b/cores/arduino/zephyrCommon.cpp index 4dd834cf..3263d8d2 100644 --- a/cores/arduino/zephyrCommon.cpp +++ b/cores/arduino/zephyrCommon.cpp @@ -140,6 +140,29 @@ const struct pwm_dt_spec arduino_pwm[] = { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), pwms, PWM_DT_SPEC) }; /* pwm-pins node provides a mapping digital pin numbers to pwm channels */ +#if 1 +static const struct gpio_dt_spec arduino_pwm_pins[] = {DT_FOREACH_PROP_ELEM_SEP( + DT_PATH(zephyr_user), pwm_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, ))}; + +size_t pwm_pin_index(pin_size_t pinNumber) { + printk("pwm_pin_index: %u: ", pinNumber); + if (pinNumber >= ARRAY_SIZE(arduino_pins)) { + return (size_t)-1; + } + printk("(%p %u):", arduino_pins[pinNumber].port, arduino_pins[pinNumber].pin); + for(size_t i=0; i; + pinctrl-names = "default"; +}; + +&timers1 { + status = "okay"; + st,prescaler = <0>; + + pwm1: pwm { + status = "okay"; + pinctrl-0 = <&tim1_ch1_pa8 &tim1_ch2_pj11>; + pinctrl-names = "default"; + }; +}; + +&timers3 { + status = "okay"; + st,prescaler = <100>; + + pwm3: pwm { + status = "okay"; + pinctrl-0 = <&tim3_ch1_pc6 &tim3_ch2_pc7>; + pinctrl-names = "default"; + }; +}; + +&timers8 { + status = "okay"; + st,prescaler = <100>; + + pwm8: pwm { + status = "okay"; + pinctrl-0 = <&tim8_ch3n_ph15 &tim8_ch2_pj10 &tim8_ch2n_pj7>; + pinctrl-names = "default"; + }; +}; + +&timers12 { + status = "okay"; + st,prescaler = <100>; + + pwm12: pwm { + status = "okay"; + pinctrl-0 = <&tim12_ch1_ph6>; + pinctrl-names = "default"; + }; +}; + +&pwm1 { + /* Use the pwmclock node to start the clock generation */ + pwmclock: pwmclock { + status = "okay"; + compatible = "pwm-clock"; + clock-frequency = <0>; + #clock-cells = <1>; + pwms = <&pwm1 1 PWM_HZ(11000000) PWM_POLARITY_NORMAL>; + //12mhz for 7670, default is also 12MHz + }; +}; + &rng { status = "okay"; }; +&dmamux1 { + status = "okay"; +}; + +&dma1 { + status = "okay"; +}; + + +&adc1 { + pinctrl-0 = <&adc1_inp12_pc2 + &adc1_inp13_pc3 + &adc1_inp18_pa4 + &adc1_inp3_pa6 + &adc1_inp0_pa0_c + &adc1_inp1_pa1_c>; + pinctrl-names = "default"; + st,adc-clock-source = ; + st,adc-prescaler = <4>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@c { + reg = <12>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@d { + reg = <13>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@12 { + reg = <18>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + + /* PA0_C and PA1_C */ + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; +}; + +&adc3 { + pinctrl-0 = <&adc3_inp0_pc2_c + &adc3_inp1_pc3_c>; + pinctrl-names = "default"; + st,adc-clock-source = ; + st,adc-prescaler = <4>; + status = "okay"; + + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; + channel@1 { + reg = <1>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <16>; + }; +}; + + / { chosen { zephyr,console = &usart6; zephyr,shell-uart = &usart6; zephyr,cdc-acm-uart0 = &usart6; }; + + /* used to overcome problems with _C analog pins */ + gpioz: gpio@deadbeef { + compatible = "vnd,gpio"; + gpio-controller; + reg = <0xdeadbeef 0x1000>; + #gpio-cells = <0x2>; + status = "okay"; + }; + }; / { @@ -66,29 +245,253 @@ / { zephyr,user { - digital-pin-gpios = <&gpioh 15 GPIO_ACTIVE_LOW>, - <&gpiok 1 GPIO_ACTIVE_LOW>, - <&gpioj 11 GPIO_ACTIVE_LOW>, - <&gpiog 7 GPIO_ACTIVE_LOW>, - <&gpioc 7 GPIO_ACTIVE_LOW>, - <&gpioc 6 GPIO_ACTIVE_LOW>, - <&gpioa 8 GPIO_ACTIVE_LOW>, - <&gpioi 0 GPIO_ACTIVE_LOW>, - <&gpioc 3 GPIO_ACTIVE_LOW>, - <&gpioi 1 GPIO_ACTIVE_LOW>, - <&gpioc 2 GPIO_ACTIVE_LOW>, - <&gpioh 8 GPIO_ACTIVE_LOW>, - <&gpioh 7 GPIO_ACTIVE_LOW>, - <&gpioa 10 GPIO_ACTIVE_LOW>, - <&gpioa 9 GPIO_ACTIVE_LOW>, - <&gpiok 5 GPIO_ACTIVE_LOW>; // LEDR + digital-pin-gpios = <&gpioh 15 0>, /* D0 */ + <&gpiok 1 0>, + <&gpioj 11 0>, + <&gpiog 7 0>, + <&gpioc 7 0>, + <&gpioc 6 0>, + <&gpioa 8 0>, + <&gpioi 0 0>, + <&gpioc 3 0>, + <&gpioi 1 0>, + <&gpioc 2 0>, + <&gpioh 8 0>, + <&gpioh 7 0>, + <&gpioa 10 0>, + <&gpioa 9 0>, /* D14 */ - builtin-led-gpios = <&gpiok 5 GPIO_ACTIVE_LOW>, - <&gpiok 6 GPIO_ACTIVE_LOW>, - <&gpiok 7 GPIO_ACTIVE_LOW>; + <&gpioz 0 0>, /* A0 ADC2_INP0 */ + <&gpioz 1 0>, /* A1 ADC2_INP1 */ + <&gpioz 2 0>, /* A2 ADC3_INP0 */ + <&gpioz 3 0>, /* A3 ADC3_INP1 */ + <&gpioc 2 0>, /* A4 _ALT0? ADC1_INP12 */ + <&gpioc 3 0>, /* A5 _ALT0? ADC1_INP13 */ + <&gpioa 4 0>, /* A6 ADC1_INP18 */ + <&gpioa 6 0>, /* A7 ADC1_INP7 */ + + + <&gpiok 5 GPIO_ACTIVE_LOW>, // LEDR + <&gpiok 6 GPIO_ACTIVE_LOW>, // LEDG + <&gpiok 7 GPIO_ACTIVE_LOW>, // LEDB + <&gpioa 0 0>, + <&gpioa 1 0>, + <&gpioa 2 0>, + <&gpioa 3 0>, + <&gpioa 4 0>, + <&gpioa 5 0>, + <&gpioa 6 0>, + <&gpioa 7 0>, + <&gpioa 8 0>, + <&gpioa 9 0>, + <&gpioa 10 0>, + <&gpioa 11 0>, + <&gpioa 12 0>, + <&gpioa 13 0>, + <&gpioa 14 0>, + <&gpioa 15 0>, + <&gpiob 0 0>, + <&gpiob 1 0>, + <&gpiob 2 0>, + <&gpiob 3 0>, + <&gpiob 4 0>, + <&gpiob 5 0>, + <&gpiob 6 0>, + <&gpiob 7 0>, + <&gpiob 8 0>, + <&gpiob 9 0>, + <&gpiob 10 0>, + <&gpiob 11 0>, + <&gpiob 12 0>, + <&gpiob 13 0>, + <&gpiob 14 0>, + <&gpiob 15 0>, + <&gpioc 0 0>, + <&gpioc 1 0>, + <&gpioc 2 0>, + <&gpioc 3 0>, + <&gpioc 4 0>, + <&gpioc 5 0>, + <&gpioc 6 0>, + <&gpioc 7 0>, + <&gpioc 8 0>, + <&gpioc 9 0>, + <&gpioc 10 0>, + <&gpioc 11 0>, + <&gpioc 12 0>, + <&gpioc 13 0>, + <&gpioc 14 0>, + <&gpioc 15 0>, + <&gpiod 0 0>, + <&gpiod 1 0>, + <&gpiod 2 0>, + <&gpiod 3 0>, + <&gpiod 4 0>, + <&gpiod 5 0>, + <&gpiod 6 0>, + <&gpiod 7 0>, + <&gpiod 8 0>, + <&gpiod 9 0>, + <&gpiod 10 0>, + <&gpiod 11 0>, + <&gpiod 12 0>, + <&gpiod 13 0>, + <&gpiod 14 0>, + <&gpiod 15 0>, + <&gpioe 0 0>, + <&gpioe 1 0>, + <&gpioe 2 0>, + <&gpioe 3 0>, + <&gpioe 4 0>, + <&gpioe 5 0>, + <&gpioe 6 0>, + <&gpioe 7 0>, + <&gpioe 8 0>, + <&gpioe 9 0>, + <&gpioe 10 0>, + <&gpioe 11 0>, + <&gpioe 12 0>, + <&gpioe 13 0>, + <&gpioe 14 0>, + <&gpioe 15 0>, + <&gpiof 0 0>, + <&gpiof 1 0>, + <&gpiof 2 0>, + <&gpiof 3 0>, + <&gpiof 4 0>, + <&gpiof 5 0>, + <&gpiof 6 0>, + <&gpiof 7 0>, + <&gpiof 8 0>, + <&gpiof 9 0>, + <&gpiof 10 0>, + <&gpiof 11 0>, + <&gpiof 12 0>, + <&gpiof 13 0>, + <&gpiof 14 0>, + <&gpiof 15 0>, + <&gpiog 0 0>, + <&gpiog 1 0>, + <&gpiog 2 0>, + <&gpiog 3 0>, + <&gpiog 4 0>, + <&gpiog 5 0>, + <&gpiog 6 0>, + <&gpiog 7 0>, + <&gpiog 8 0>, + <&gpiog 9 0>, + <&gpiog 10 0>, + <&gpiog 11 0>, + <&gpiog 12 0>, + <&gpiog 13 0>, + <&gpiog 14 0>, + <&gpiog 15 0>, + <&gpioh 0 0>, + <&gpioh 1 0>, + <&gpioh 2 0>, + <&gpioh 3 0>, + <&gpioh 4 0>, + <&gpioh 5 0>, + <&gpioh 6 0>, + <&gpioh 7 0>, + <&gpioh 8 0>, + <&gpioh 9 0>, + <&gpioh 10 0>, + <&gpioh 11 0>, + <&gpioh 12 0>, + <&gpioh 13 0>, + <&gpioh 14 0>, + <&gpioh 15 0>, + <&gpioi 0 0>, + <&gpioi 1 0>, + <&gpioi 2 0>, + <&gpioi 3 0>, + <&gpioi 4 0>, + <&gpioi 5 0>, + <&gpioi 6 0>, + <&gpioi 7 0>, + <&gpioi 8 0>, + <&gpioi 9 0>, + <&gpioi 10 0>, + <&gpioi 11 0>, + <&gpioi 12 0>, + <&gpioi 13 0>, + <&gpioi 14 0>, + <&gpioi 15 0>, + <&gpioj 0 0>, + <&gpioj 1 0>, + <&gpioj 2 0>, + <&gpioj 3 0>, + <&gpioj 4 0>, + <&gpioj 5 0>, + <&gpioj 6 0>, + <&gpioj 7 0>, + <&gpioj 8 0>, + <&gpioj 9 0>, + <&gpioj 10 0>, + <&gpioj 11 0>, + <&gpioj 12 0>, + <&gpioj 13 0>, + <&gpioj 14 0>, + <&gpioj 15 0>, + <&gpiok 0 0>, + <&gpiok 1 0>, + <&gpiok 2 0>, + <&gpiok 3 0>, + <&gpiok 4 0>; + + /* commented out for now to allow LEDs to work + /* <&gpiok 5 0>, */ + /* <&gpiok 6 0>, */ + /* <&gpiok 7 0>; */ + + + + builtin-led-gpios = <&gpiok 5 GPIO_ACTIVE_LOW>, + <&gpiok 6 GPIO_ACTIVE_LOW>, + <&gpiok 7 GPIO_ACTIVE_LOW>; + + pwm-pin-gpios = <&gpioa 8 0>, + <&gpioc 6 0>, + <&gpioc 7 0>, + //<&gpiog 7 0>, + <&gpioj 11 0>, + //<&gpiok 1 0>, + <&gpioh 15 0>, + <&gpioj 7 0>, + <&gpioj 10 0>, + <&gpioh 6 0>; + + adc-pin-gpios = <&gpioz 0 0>, /* analog only */ + <&gpioz 1 0>, /* analog only */ + <&gpioz 2 0>, /* analog only */ + <&gpioz 3 0>, /* analog only */ + <&gpioc 2 0>, + <&gpioc 3 0>, + <&gpioa 4 0>, + <&gpioa 6 0>; + serials = <&cdc_acm_uart0>,<&usart6>, <&usart1>, <&uart4>; cdc-acm = <&cdc_acm_uart0>; - i2cs = <&i2c4>; + i2cs = <&i2c3>, <&i2c1>, <&i2c4>; + spis = <&spi2>; + pwms = <&pwm1 1 PWM_HZ(11000000) PWM_POLARITY_NORMAL>, //12mhz default + <&pwm3 1 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm3 2 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm1 2 PWM_HZ(5000) PWM_POLARITY_NORMAL>, + <&pwm8 3 PWM_HZ(500) PWM_POLARITY_INVERTED>, + <&pwm8 2 PWM_HZ(500) PWM_POLARITY_INVERTED>, + <&pwm8 2 PWM_HZ(500) PWM_POLARITY_NORMAL>, + <&pwm12 1 PWM_HZ(500) PWM_POLARITY_NORMAL>; + + io-channels = <&adc1 0>, + <&adc1 1>, + <&adc3 0>, + <&adc3 1>, + <&adc1 12>, + <&adc1 13>, + <&adc1 18>, + <&adc1 3>; }; }; diff --git a/variants/arduino_portenta_h7/pure_analog_pins.cpp b/variants/arduino_portenta_h7/pure_analog_pins.cpp new file mode 100644 index 00000000..83548487 --- /dev/null +++ b/variants/arduino_portenta_h7/pure_analog_pins.cpp @@ -0,0 +1,17 @@ +#include "pure_analog_pins.h" + +#undef A0 +#undef A1 +#undef A2 +#undef A3 + +PureAnalogPin A0_PURE(0); +PureAnalogPin A1_PURE(1); +PureAnalogPin A2_PURE(2); +PureAnalogPin A3_PURE(3); + +int getAnalogReadResolution(); + +int analogRead(PureAnalogPin pin) { + return ::analogRead(A0 + pin.get()); +} diff --git a/variants/arduino_portenta_h7/pure_analog_pins.h b/variants/arduino_portenta_h7/pure_analog_pins.h new file mode 100644 index 00000000..b949a069 --- /dev/null +++ b/variants/arduino_portenta_h7/pure_analog_pins.h @@ -0,0 +1,57 @@ +#ifndef _PURE_ANALOG_PINS_ +#define _PURE_ANALOG_PINS_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include "Arduino.h" + +/****************************************************************************** + * PREPROCESSOR-MAGIC + ******************************************************************************/ + +#define PURE_ANALOG_AS_DIGITAL_ATTRIBUTE __attribute__ ((error("Can't use pins A0-A3 as digital"))) + +/****************************************************************************** + * TYPEDEF + ******************************************************************************/ + +class PureAnalogPin { +public: + PureAnalogPin(int _pin) : pin(_pin) {}; + int get() { + return pin; + }; + bool operator== (PureAnalogPin const & other) const { + return pin == other.pin; + } + //operator int() = delete; + __attribute__ ((error("Change me to a #define"))) operator int(); +private: + int pin; +}; + +extern PureAnalogPin A0_PURE; +extern PureAnalogPin A1_PURE; +extern PureAnalogPin A2_PURE; +extern PureAnalogPin A3_PURE; + +#define A0 A0_PURE +#define A1 A1_PURE +#define A2 A2_PURE +#define A3 A3_PURE + +/****************************************************************************** + * FUNCTION DECLARATION + ******************************************************************************/ + +void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE pinMode (PureAnalogPin pin, PinMode mode); +PinStatus PURE_ANALOG_AS_DIGITAL_ATTRIBUTE digitalRead (PureAnalogPin pin); +void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE digitalWrite(PureAnalogPin pin, PinStatus value); +int analogRead (PureAnalogPin pin); +void PURE_ANALOG_AS_DIGITAL_ATTRIBUTE analogWrite (PureAnalogPin pin, int value); + +#undef PURE_ANALOG_AS_DIGITAL_ATTRIBUTE + +#endif /* _PURE_ANALOG_PINS_ */ diff --git a/variants/arduino_portenta_h7/variant.h b/variants/arduino_portenta_h7/variant.h index 68c33a89..9c1abf2e 100644 --- a/variants/arduino_portenta_h7/variant.h +++ b/variants/arduino_portenta_h7/variant.h @@ -3,6 +3,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include "pure_analog_pins.h" // TODO: correctly handle these legacy defines #define MOSI 0 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy