diff options
Diffstat (limited to 'platforms')
| -rw-r--r-- | platforms/avr/drivers/analog.c | 23 | ||||
| -rw-r--r-- | platforms/avr/drivers/analog.h | 1 | ||||
| -rw-r--r-- | platforms/chibios/drivers/i2c_master.c | 12 | ||||
| -rw-r--r-- | platforms/chibios/drivers/i2c_master.h | 21 |
4 files changed, 10 insertions, 47 deletions
diff --git a/platforms/avr/drivers/analog.c b/platforms/avr/drivers/analog.c index 8d299ffdb..628835cce 100644 --- a/platforms/avr/drivers/analog.c +++ b/platforms/avr/drivers/analog.c | |||
| @@ -23,29 +23,6 @@ static uint8_t aref = ADC_REF_POWER; | |||
| 23 | 23 | ||
| 24 | void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); } | 24 | void analogReference(uint8_t mode) { aref = mode & (_BV(REFS1) | _BV(REFS0)); } |
| 25 | 25 | ||
| 26 | // Arduino compatible pin input | ||
| 27 | int16_t analogRead(uint8_t pin) { | ||
| 28 | #if defined(__AVR_ATmega32U4__) | ||
| 29 | // clang-format off | ||
| 30 | static const uint8_t PROGMEM pin_to_mux[] = { | ||
| 31 | //A0 A1 A2 A3 A4 A5 | ||
| 32 | //F7 F6 F5 F4 F1 F0 | ||
| 33 | 0x07, 0x06, 0x05, 0x04, 0x01, 0x00, | ||
| 34 | //A6 A7 A8 A9 A10 A11 | ||
| 35 | //D4 D7 B4 B5 B6 D6 | ||
| 36 | 0x20, 0x22, 0x23, 0x24, 0x25, 0x21 | ||
| 37 | }; | ||
| 38 | // clang-format on | ||
| 39 | if (pin >= 12) return 0; | ||
| 40 | return adc_read(pgm_read_byte(pin_to_mux + pin)); | ||
| 41 | #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__) | ||
| 42 | if (pin >= 8) return 0; | ||
| 43 | return adc_read(pin); | ||
| 44 | #else | ||
| 45 | return 0; | ||
| 46 | #endif | ||
| 47 | } | ||
| 48 | |||
| 49 | int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); } | 26 | int16_t analogReadPin(pin_t pin) { return adc_read(pinToMux(pin)); } |
| 50 | 27 | ||
| 51 | uint8_t pinToMux(pin_t pin) { | 28 | uint8_t pinToMux(pin_t pin) { |
diff --git a/platforms/avr/drivers/analog.h b/platforms/avr/drivers/analog.h index 058882450..b3c05e197 100644 --- a/platforms/avr/drivers/analog.h +++ b/platforms/avr/drivers/analog.h | |||
| @@ -23,7 +23,6 @@ | |||
| 23 | extern "C" { | 23 | extern "C" { |
| 24 | #endif | 24 | #endif |
| 25 | void analogReference(uint8_t mode); | 25 | void analogReference(uint8_t mode); |
| 26 | int16_t analogRead(uint8_t pin); | ||
| 27 | 26 | ||
| 28 | int16_t analogReadPin(pin_t pin); | 27 | int16_t analogReadPin(pin_t pin); |
| 29 | uint8_t pinToMux(pin_t pin); | 28 | uint8_t pinToMux(pin_t pin); |
diff --git a/platforms/chibios/drivers/i2c_master.c b/platforms/chibios/drivers/i2c_master.c index fc4bb2ab3..9af5c71c3 100644 --- a/platforms/chibios/drivers/i2c_master.c +++ b/platforms/chibios/drivers/i2c_master.c | |||
| @@ -63,16 +63,16 @@ __attribute__((weak)) void i2c_init(void) { | |||
| 63 | is_initialised = true; | 63 | is_initialised = true; |
| 64 | 64 | ||
| 65 | // Try releasing special pins for a short time | 65 | // Try releasing special pins for a short time |
| 66 | palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT); | 66 | palSetLineMode(I2C1_SCL_PIN, PAL_MODE_INPUT); |
| 67 | palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT); | 67 | palSetLineMode(I2C1_SDA_PIN, PAL_MODE_INPUT); |
| 68 | 68 | ||
| 69 | chThdSleepMilliseconds(10); | 69 | chThdSleepMilliseconds(10); |
| 70 | #if defined(USE_GPIOV1) | 70 | #if defined(USE_GPIOV1) |
| 71 | palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, I2C1_SCL_PAL_MODE); | 71 | palSetLineMode(I2C1_SCL_PIN, I2C1_SCL_PAL_MODE); |
| 72 | palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, I2C1_SDA_PAL_MODE); | 72 | palSetLineMode(I2C1_SDA_PIN, I2C1_SDA_PAL_MODE); |
| 73 | #else | 73 | #else |
| 74 | palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | 74 | palSetLineMode(I2C1_SCL_PIN, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); |
| 75 | palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); | 75 | palSetLineMode(I2C1_SDA_PIN, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN); |
| 76 | #endif | 76 | #endif |
| 77 | } | 77 | } |
| 78 | } | 78 | } |
diff --git a/platforms/chibios/drivers/i2c_master.h b/platforms/chibios/drivers/i2c_master.h index c68109acb..303aa6990 100644 --- a/platforms/chibios/drivers/i2c_master.h +++ b/platforms/chibios/drivers/i2c_master.h | |||
| @@ -27,24 +27,11 @@ | |||
| 27 | #include <ch.h> | 27 | #include <ch.h> |
| 28 | #include <hal.h> | 28 | #include <hal.h> |
| 29 | 29 | ||
| 30 | #ifdef I2C1_BANK | 30 | #ifndef I2C1_SCL_PIN |
| 31 | # define I2C1_SCL_BANK I2C1_BANK | 31 | # define I2C1_SCL_PIN B6 |
| 32 | # define I2C1_SDA_BANK I2C1_BANK | ||
| 33 | #endif | 32 | #endif |
| 34 | 33 | #ifndef I2C1_SDA_PIN | |
| 35 | #ifndef I2C1_SCL_BANK | 34 | # define I2C1_SDA_PIN B7 |
| 36 | # define I2C1_SCL_BANK GPIOB | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifndef I2C1_SDA_BANK | ||
| 40 | # define I2C1_SDA_BANK GPIOB | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifndef I2C1_SCL | ||
| 44 | # define I2C1_SCL 6 | ||
| 45 | #endif | ||
| 46 | #ifndef I2C1_SDA | ||
| 47 | # define I2C1_SDA 7 | ||
| 48 | #endif | 35 | #endif |
| 49 | 36 | ||
| 50 | #ifdef USE_I2CV1 | 37 | #ifdef USE_I2CV1 |
