Skip to content

Commit

Permalink
Merge pull request MarlinFirmware#8227 from tcm0116/2.0.x-pin_mapping
Browse files Browse the repository at this point in the history
LPC1768: updates to use the new pin_t typedef
  • Loading branch information
thinkyhead authored Nov 3, 2017
2 parents 3749a74 + 13d8397 commit 8735ae9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 54 deletions.
17 changes: 9 additions & 8 deletions Marlin/src/HAL/HAL_LPC1768/LPC1768_PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,\
Expand Down Expand Up @@ -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};
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -506,4 +508,3 @@ return;
* NOTE - PCR must be set before PINSEL
* sets the pins controlled by the ISR to their active states
*/

6 changes: 3 additions & 3 deletions Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/HAL/HAL_LPC1768/SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -74,8 +74,8 @@ class SoftwareSerial : public Stream
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
Expand All @@ -84,7 +84,7 @@ class SoftwareSerial : public Stream
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();
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/HAL_LPC1768/WInterrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/HAL/HAL_LPC1768/pinmapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/HAL/HAL_LPC1768/watchdog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 16 additions & 16 deletions frameworks/CMSIS/LPC1768/lib/LiquidCrystal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 19 additions & 18 deletions frameworks/CMSIS/LPC1768/lib/LiquidCrystal.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <inttypes.h>
#include "binary.h"
#include "Print.h"
#include <HAL_LPC1768/pinmapping.h>

// commands
#define LCD_CLEARDISPLAY 0x01
Expand Down Expand Up @@ -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);

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);
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, 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);

Expand Down Expand Up @@ -91,10 +92,10 @@ class LiquidCrystal : public Print {
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;
Expand Down

0 comments on commit 8735ae9

Please sign in to comment.