Merge pull request #8227 from tcm0116/2.0.x-pin_mapping

LPC1768: updates to use the new pin_t typedef
This commit is contained in:
Scott Lahteine 2017-11-03 03:10:19 -05:00 committed by GitHub
commit 8735ae984b
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 53 deletions

View file

@ -90,7 +90,7 @@ typedef struct { // holds all data needed to control/init one of the
#define MICRO_MAX 0xffffffff #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,\ #define PWM_MAP_INIT {PWM_MAP_INIT_ROW,\
PWM_MAP_INIT_ROW,\ 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]; MR_map map_MR[NUM_PWMS];
void LPC1768_PWM_update_map_MR(void) { 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[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), 11, &LPC_PWM1->MR2, 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), 6, &LPC_PWM1->MR3, 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, 0, &LPC_PWM1->MR4, 0, 0}; map_MR[3] = {0, 0, P_NC, &LPC_PWM1->MR4, 0, 0};
map_MR[4] = {0, 0, 0, &LPC_PWM1->MR5, 0, 0}; map_MR[4] = {0, 0, P_NC, &LPC_PWM1->MR5, 0, 0};
map_MR[5] = {0, 0, 0, &LPC_PWM1->MR6, 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].PINSEL3_bits = 0;
map_MR[pin_4_PWM_channel - 1].map_PWM_INT = 0; // 0 - available for interrupts, 1 - in use by PWM map_MR[pin_4_PWM_channel - 1].map_PWM_INT = 0; // 0 - available for interrupts, 1 - in use by PWM
break; break;
default:
break;
} }
pinMode(pin, INPUT); pinMode(pin, INPUT);
@ -506,4 +508,3 @@ return;
* NOTE - PCR must be set before PINSEL * NOTE - PCR must be set before PINSEL
* sets the pins controlled by the ISR to their active states * sets the pins controlled by the ISR to their active states
*/ */

View file

@ -212,7 +212,7 @@ extern "C" void intWrapper() {
// //
// Constructor // 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_centering(0),
_rx_delay_intrabit(0), _rx_delay_intrabit(0),
_rx_delay_stopbit(0), _rx_delay_stopbit(0),
@ -233,7 +233,7 @@ SoftwareSerial::~SoftwareSerial()
end(); 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, // 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 // 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! pinMode(rx, INPUT_PULLUP); // pullup for normal logic!
//if (!_inverse_logic) //if (!_inverse_logic)

View file

@ -48,8 +48,8 @@ class SoftwareSerial : public Stream
{ {
private: private:
// per object data // per object data
uint8_t _receivePin; pin_t _receivePin;
uint8_t _transmitPin; pin_t _transmitPin;
// uint32_t _receiveBitMask; // for rx interrupts // uint32_t _receiveBitMask; // for rx interrupts
uint32_t _receivePort; uint32_t _receivePort;
uint32_t _receivePortPin; uint32_t _receivePortPin;
@ -74,8 +74,8 @@ private:
void recv(); void recv();
uint32_t rx_pin_read(); uint32_t rx_pin_read();
void tx_pin_write(uint8_t pin_state); void tx_pin_write(uint8_t pin_state);
void setTX(uint8_t transmitPin); void setTX(pin_t transmitPin);
void setRX(uint8_t receivePin); void setRX(pin_t receivePin);
void setRxIntMsk(bool enable); void setRxIntMsk(bool enable);
// private static method for timing // private static method for timing
@ -84,7 +84,7 @@ private:
public: public:
// public methods // 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(); ~SoftwareSerial();
void begin(long speed); void begin(long speed);
bool listen(); bool listen();

View file

@ -45,7 +45,7 @@ static void __initialize() {
NVIC_EnableIRQ(EINT3_IRQn); 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; static int enabled = 0;
if (!INTERRUPT_PIN(pin)) return; 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); GpioEnableInt(myport,mypin,mode);
} }
void detachInterrupt(const uint32_t pin) { void detachInterrupt(const pin_t pin) {
if (!INTERRUPT_PIN(pin)) return; if (!INTERRUPT_PIN(pin)) return;
const uint8_t myport = LPC1768_PIN_PORT(pin), const uint8_t myport = LPC1768_PIN_PORT(pin),

View file

@ -103,6 +103,8 @@ constexpr int8_t LPC1768_PIN_ADC(const pin_t pin) { return (int8_t)((pin >> 10)
// ****************** // ******************
// Runtime pinmapping // Runtime pinmapping
// ****************** // ******************
#define P_NC -1
#if SERIAL_PORT != 3 #if SERIAL_PORT != 3
#define P0_0 LPC1768_PIN(PORT(0), PIN(0), INTERRUPT(1), PWM(0), ADC_NONE) #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) #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) { 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) { constexpr int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p) {

View file

@ -43,7 +43,9 @@ uint8_t HAL_get_reset_source(void) {
void watchdog_reset() { void watchdog_reset() {
WDT_Feed(); WDT_Feed();
TOGGLE(13); // heart beat indicator on Pin13 #if PIN_EXISTS(LED)
TOGGLE(LED_PIN); // heart beat indicator
#endif
} }
#endif // TARGET_LPC1768 #endif // TARGET_LPC1768

View file

@ -24,35 +24,35 @@
// can't assume that its in that state when a sketch starts (and the // can't assume that its in that state when a sketch starts (and the
// LiquidCrystal constructor is called). // LiquidCrystal constructor is called).
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, LiquidCrystal::LiquidCrystal(pin_t rs, pin_t rw, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, pin_t d0, pin_t d1, pin_t d2, pin_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) 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); init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7);
} }
LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, LiquidCrystal::LiquidCrystal(pin_t rs, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, pin_t d0, pin_t d1, pin_t d2, pin_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) 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, LiquidCrystal::LiquidCrystal(pin_t rs, pin_t rw, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) 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, LiquidCrystal::LiquidCrystal(pin_t rs, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) 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, void LiquidCrystal::init(uint8_t fourbitmode, pin_t rs, pin_t rw, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, pin_t d0, pin_t d1, pin_t d2, pin_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) pin_t d4, pin_t d5, pin_t d6, pin_t d7)
{ {
_rs_pin = rs; _rs_pin = rs;
_rw_pin = rw; _rw_pin = rw;

View file

@ -4,6 +4,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "binary.h" #include "binary.h"
#include "Print.h" #include "Print.h"
#include <HAL_LPC1768/pinmapping.h>
// commands // commands
#define LCD_CLEARDISPLAY 0x01 #define LCD_CLEARDISPLAY 0x01
@ -45,20 +46,20 @@
class LiquidCrystal : public Print { class LiquidCrystal : public Print {
public: public:
LiquidCrystal(uint8_t rs, uint8_t enable, LiquidCrystal(pin_t rs, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, pin_t d0, pin_t d1, pin_t d2, pin_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); pin_t d4, pin_t d5, pin_t d6, pin_t d7);
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, LiquidCrystal(pin_t rs, pin_t rw, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, pin_t d0, pin_t d1, pin_t d2, pin_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); pin_t d4, pin_t d5, pin_t d6, pin_t d7);
LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, LiquidCrystal(pin_t rs, pin_t rw, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); pin_t d0, pin_t d1, pin_t d2, pin_t d3);
LiquidCrystal(uint8_t rs, uint8_t enable, LiquidCrystal(pin_t rs, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); 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, void init(uint8_t fourbitmode, pin_t rs, pin_t rw, pin_t enable,
uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, pin_t d0, pin_t d1, pin_t d2, pin_t d3,
uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); 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); void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
@ -91,10 +92,10 @@ private:
void write8bits(uint8_t); void write8bits(uint8_t);
void pulseEnable(); void pulseEnable();
uint8_t _rs_pin; // LOW: command. HIGH: character. pin_t _rs_pin; // LOW: command. HIGH: character.
uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. pin_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD.
uint8_t _enable_pin; // activated by a HIGH pulse. pin_t _enable_pin; // activated by a HIGH pulse.
uint8_t _data_pins[8]; pin_t _data_pins[8];
uint8_t _displayfunction; uint8_t _displayfunction;
uint8_t _displaycontrol; uint8_t _displaycontrol;