From 13d839795cb9ec0d81e1f3e8517e1f2e12fe4714 Mon Sep 17 00:00:00 2001 From: Thomas Moore Date: Thu, 2 Nov 2017 18:43:57 -0500 Subject: [PATCH] LPC1768: updates to use the new pin_t typedef --- Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp | 17 ++++----- Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp | 6 ++-- Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h | 10 +++--- Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp | 4 +-- Marlin/src/HAL/HAL_LPC1768/pinmapping.h | 4 ++- Marlin/src/HAL/HAL_LPC1768/watchdog.cpp | 4 ++- .../CMSIS/LPC1768/lib/LiquidCrystal.cpp | 32 ++++++++--------- frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h | 35 ++++++++++--------- 8 files changed, 59 insertions(+), 53 deletions(-) diff --git a/Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp b/Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp index 65cfb56635..7b2101b2a3 100644 --- a/Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp @@ -90,7 +90,7 @@ typedef struct { // holds all data needed to control/init one of the #define MICRO_MAX 0xffffffff -#define PWM_MAP_INIT_ROW {0, 0xff, 0, 0, 0, 0, MICRO_MAX, 0, 0, 0, 0, 0, 0, 0, 0} +#define PWM_MAP_INIT_ROW {0, P_NC, 0, 0, 0, 0, MICRO_MAX, 0, 0, 0, 0, 0, 0, 0, 0} #define PWM_MAP_INIT {PWM_MAP_INIT_ROW,\ PWM_MAP_INIT_ROW,\ PWM_MAP_INIT_ROW,\ @@ -234,12 +234,12 @@ typedef struct { // status of PWM1 channel MR_map map_MR[NUM_PWMS]; void LPC1768_PWM_update_map_MR(void) { - map_MR[0] = {0, (uint8_t) (LPC_PWM1->PCR & _BV(8 + pin_4_PWM_channel) ? 1 : 0), 4, &LPC_PWM1->MR1, 0, 0}; - map_MR[1] = {0, (uint8_t) (LPC_PWM1->PCR & _BV(8 + pin_11_PWM_channel) ? 1 : 0), 11, &LPC_PWM1->MR2, 0, 0}; - map_MR[2] = {0, (uint8_t) (LPC_PWM1->PCR & _BV(8 + pin_6_PWM_channel) ? 1 : 0), 6, &LPC_PWM1->MR3, 0, 0}; - map_MR[3] = {0, 0, 0, &LPC_PWM1->MR4, 0, 0}; - map_MR[4] = {0, 0, 0, &LPC_PWM1->MR5, 0, 0}; - map_MR[5] = {0, 0, 0, &LPC_PWM1->MR6, 0, 0}; + map_MR[0] = {0, (uint8_t) (LPC_PWM1->PCR & _BV(8 + pin_4_PWM_channel) ? 1 : 0), P1_18, &LPC_PWM1->MR1, 0, 0}; + map_MR[1] = {0, (uint8_t) (LPC_PWM1->PCR & _BV(8 + pin_11_PWM_channel) ? 1 : 0), P1_20, &LPC_PWM1->MR2, 0, 0}; + map_MR[2] = {0, (uint8_t) (LPC_PWM1->PCR & _BV(8 + pin_6_PWM_channel) ? 1 : 0), P1_21, &LPC_PWM1->MR3, 0, 0}; + map_MR[3] = {0, 0, P_NC, &LPC_PWM1->MR4, 0, 0}; + map_MR[4] = {0, 0, P_NC, &LPC_PWM1->MR5, 0, 0}; + map_MR[5] = {0, 0, P_NC, &LPC_PWM1->MR6, 0, 0}; } @@ -384,6 +384,8 @@ bool LPC1768_PWM_detach_pin(pin_t pin) { map_MR[pin_4_PWM_channel - 1].PINSEL3_bits = 0; map_MR[pin_4_PWM_channel - 1].map_PWM_INT = 0; // 0 - available for interrupts, 1 - in use by PWM break; + default: + break; } pinMode(pin, INPUT); @@ -506,4 +508,3 @@ return; * NOTE - PCR must be set before PINSEL * sets the pins controlled by the ISR to their active states */ - diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp index 21796bcf64..a293402889 100644 --- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp @@ -212,7 +212,7 @@ extern "C" void intWrapper() { // // Constructor // -SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : +SoftwareSerial::SoftwareSerial(pin_t receivePin, pin_t transmitPin, bool inverse_logic /* = false */) : _rx_delay_centering(0), _rx_delay_intrabit(0), _rx_delay_stopbit(0), @@ -233,7 +233,7 @@ SoftwareSerial::~SoftwareSerial() end(); } -void SoftwareSerial::setTX(uint8_t tx) +void SoftwareSerial::setTX(pin_t tx) { // First write, then set output. If we do this the other way around, // the pin would be output low for a short while before switching to @@ -246,7 +246,7 @@ void SoftwareSerial::setTX(uint8_t tx) } -void SoftwareSerial::setRX(uint8_t rx) +void SoftwareSerial::setRX(pin_t rx) { pinMode(rx, INPUT_PULLUP); // pullup for normal logic! //if (!_inverse_logic) diff --git a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h index f581882f33..2b8c306ce6 100644 --- a/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h +++ b/Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h @@ -48,8 +48,8 @@ class SoftwareSerial : public Stream { private: // per object data - uint8_t _receivePin; - uint8_t _transmitPin; + pin_t _receivePin; + pin_t _transmitPin; // uint32_t _receiveBitMask; // for rx interrupts uint32_t _receivePort; uint32_t _receivePortPin; @@ -74,8 +74,8 @@ private: void recv(); uint32_t rx_pin_read(); void tx_pin_write(uint8_t pin_state); - void setTX(uint8_t transmitPin); - void setRX(uint8_t receivePin); + void setTX(pin_t transmitPin); + void setRX(pin_t receivePin); void setRxIntMsk(bool enable); // private static method for timing @@ -84,7 +84,7 @@ private: public: // public methods - SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false); + SoftwareSerial(pin_t receivePin, pin_t transmitPin, bool inverse_logic = false); ~SoftwareSerial(); void begin(long speed); bool listen(); diff --git a/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp b/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp index f1cf6f9838..3c7a469fd7 100644 --- a/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp @@ -45,7 +45,7 @@ static void __initialize() { NVIC_EnableIRQ(EINT3_IRQn); } -void attachInterrupt(const uint32_t pin, void (*callback)(void), uint32_t mode) { +void attachInterrupt(const pin_t pin, void (*callback)(void), uint32_t mode) { static int enabled = 0; if (!INTERRUPT_PIN(pin)) return; @@ -66,7 +66,7 @@ void attachInterrupt(const uint32_t pin, void (*callback)(void), uint32_t mode) GpioEnableInt(myport,mypin,mode); } -void detachInterrupt(const uint32_t pin) { +void detachInterrupt(const pin_t pin) { if (!INTERRUPT_PIN(pin)) return; const uint8_t myport = LPC1768_PIN_PORT(pin), diff --git a/Marlin/src/HAL/HAL_LPC1768/pinmapping.h b/Marlin/src/HAL/HAL_LPC1768/pinmapping.h index c99b1188de..76efe3c0df 100644 --- a/Marlin/src/HAL/HAL_LPC1768/pinmapping.h +++ b/Marlin/src/HAL/HAL_LPC1768/pinmapping.h @@ -103,6 +103,8 @@ constexpr int8_t LPC1768_PIN_ADC(const pin_t pin) { return (int8_t)((pin >> 10) // ****************** // Runtime pinmapping // ****************** +#define P_NC -1 + #if SERIAL_PORT != 3 #define P0_0 LPC1768_PIN(PORT(0), PIN(0), INTERRUPT(1), PWM(0), ADC_NONE) #define P0_1 LPC1768_PIN(PORT(0), PIN(1), INTERRUPT(1), PWM(0), ADC_NONE) @@ -231,7 +233,7 @@ constexpr pin_t adc_pin_table[] = { }; constexpr pin_t analogInputToDigitalPin(const uint8_t p) { - return (p < COUNT(adc_pin_table) ? adc_pin_table[p] : -1); + return (p < COUNT(adc_pin_table) ? adc_pin_table[p] : P_NC); } constexpr int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p) { diff --git a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp index 21cdb2070f..d039dac1f3 100644 --- a/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/watchdog.cpp @@ -43,7 +43,9 @@ uint8_t HAL_get_reset_source(void) { void watchdog_reset() { WDT_Feed(); - TOGGLE(13); // heart beat indicator on Pin13 + #if PIN_EXISTS(LED) + TOGGLE(LED_PIN); // heart beat indicator + #endif } #endif // TARGET_LPC1768 diff --git a/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp b/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp index 4421772141..b2b8c9c370 100644 --- a/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp +++ b/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp @@ -24,35 +24,35 @@ // can't assume that its in that state when a sketch starts (and the // LiquidCrystal constructor is called). -LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, - uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +LiquidCrystal::LiquidCrystal(pin_t rs, pin_t rw, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3, + pin_t d4, pin_t d5, pin_t d6, pin_t d7) { init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); } -LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, - uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +LiquidCrystal::LiquidCrystal(pin_t rs, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3, + pin_t d4, pin_t d5, pin_t d6, pin_t d7) { - init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); + init(0, rs, P_NC, enable, d0, d1, d2, d3, d4, d5, d6, d7); } -LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +LiquidCrystal::LiquidCrystal(pin_t rs, pin_t rw, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3) { - init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); + init(1, rs, rw, enable, d0, d1, d2, d3, P_NC, P_NC, P_NC, P_NC); } -LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +LiquidCrystal::LiquidCrystal(pin_t rs, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3) { - init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); + init(1, rs, P_NC, enable, d0, d1, d2, d3, P_NC, P_NC, P_NC, P_NC); } -void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, - uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +void LiquidCrystal::init(uint8_t fourbitmode, pin_t rs, pin_t rw, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3, + pin_t d4, pin_t d5, pin_t d6, pin_t d7) { _rs_pin = rs; _rw_pin = rw; diff --git a/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h b/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h index cf51af4ace..57fe82fe8b 100644 --- a/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h +++ b/frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h @@ -4,6 +4,7 @@ #include #include "binary.h" #include "Print.h" +#include // commands #define LCD_CLEARDISPLAY 0x01 @@ -45,20 +46,20 @@ class LiquidCrystal : public Print { public: - LiquidCrystal(uint8_t rs, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, - uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); - LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, - uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); - LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); - LiquidCrystal(uint8_t rs, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + LiquidCrystal(pin_t rs, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3, + pin_t d4, pin_t d5, pin_t d6, pin_t d7); + LiquidCrystal(pin_t rs, pin_t rw, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3, + pin_t d4, pin_t d5, pin_t d6, pin_t d7); + LiquidCrystal(pin_t rs, pin_t rw, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3); + LiquidCrystal(pin_t rs, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3); - void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, - uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, - uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + void init(uint8_t fourbitmode, pin_t rs, pin_t rw, pin_t enable, + pin_t d0, pin_t d1, pin_t d2, pin_t d3, + pin_t d4, pin_t d5, pin_t d6, pin_t d7); void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); @@ -91,10 +92,10 @@ private: void write8bits(uint8_t); void pulseEnable(); - uint8_t _rs_pin; // LOW: command. HIGH: character. - uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. - uint8_t _enable_pin; // activated by a HIGH pulse. - uint8_t _data_pins[8]; + pin_t _rs_pin; // LOW: command. HIGH: character. + pin_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. + pin_t _enable_pin; // activated by a HIGH pulse. + pin_t _data_pins[8]; uint8_t _displayfunction; uint8_t _displaycontrol;