Skip to content

Commit a2e6fb2

Browse files
authored
Fix Marlin API (#47)
* update function names in Marlin api * update Arduino impl
1 parent f95fc09 commit a2e6fb2

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

include/pinmapping.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ constexpr pin_t analogInputToDigitalPin(const int8_t p) {
4646
int16_t GET_PIN_MAP_INDEX(const pin_t pin);
4747

4848
// Test whether the pin is valid
49-
bool VALID_PIN(const pin_t p);
49+
bool isValidPin(const pin_t p);
5050

5151
// Get the analog index for a digital pin
52-
int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p);
52+
int8_t digitalPinToAnalogIndex(const pin_t p);
5353

5454
// Test whether the pin is PWM
5555
bool PWM_PIN(const pin_t p);

src/MarlinSimulator/marlin_arduino_impl/arduino.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,28 @@ extern "C" void delay(const int msec) {
5757
// IO functions
5858
// As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
5959
void pinMode(const pin_t pin, const uint8_t mode) {
60-
if (!VALID_PIN(pin)) return;
60+
if (!isValidPin(pin)) return;
6161
Gpio::setMode(pin, mode);
6262
}
6363

6464
void digitalWrite(pin_t pin, uint8_t pin_status) {
65-
if (!VALID_PIN(pin)) return;
65+
if (!isValidPin(pin)) return;
6666
Gpio::set(pin, pin_status);
6767
}
6868

6969
bool digitalRead(pin_t pin) {
70-
if (!VALID_PIN(pin)) return false;
70+
if (!isValidPin(pin)) return false;
7171
return Gpio::get(pin);
7272
}
7373

7474
void analogWrite(pin_t pin, int pwm_value) { // 1 - 254: pwm_value, 0: LOW, 255: HIGH
75-
if (!VALID_PIN(pin)) return;
75+
if (!isValidPin(pin)) return;
7676
Gpio::set(pin, pwm_value);
7777
}
7878

7979
uint16_t analogRead(pin_t adc_pin) {
80-
if (!VALID_PIN(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin))) return 0;
81-
return Gpio::get(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin));
80+
if (!isValidPin(digitalPinToAnalogIndex(adc_pin))) return 0;
81+
return Gpio::get(digitalPinToAnalogIndex(adc_pin));
8282
}
8383

8484
char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s) {

src/MarlinSimulator/marlin_arduino_impl/pinmapping.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ int16_t GET_PIN_MAP_INDEX(const pin_t pin) {
3030
}
3131

3232
// Test whether the pin is valid
33-
bool VALID_PIN(const pin_t p) {
33+
bool isValidPin(const pin_t p) {
3434
return WITHIN(p, 0, NUM_DIGITAL_PINS);
3535
}
3636

3737
// Get the analog index for a digital pin
38-
int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p) {
38+
int8_t digitalPinToAnalogIndex(const pin_t p) {
3939
return (WITHIN(p, analog_offset, NUM_DIGITAL_PINS) ? p - analog_offset : P_NC);
4040
}
4141

src/MarlinSimulator/marlin_hal_impl/HAL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool MarlinHAL::adc_ready() {
6666

6767
uint16_t MarlinHAL::adc_value() {
6868
pin_t pin = analogInputToDigitalPin(active_ch);
69-
if (!VALID_PIN(pin)) return 0;
69+
if (!isValidPin(pin)) return 0;
7070
uint16_t data = ((Gpio::get(pin) >> 2) & 0x3FF);
7171
return data; // return 10bit value as Marlin expects
7272
}

0 commit comments

Comments
 (0)