mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-03-03 05:54:11 +01:00
Compare commits
1 Commits
2.1.2.7
...
latest-2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e890b686b7 |
@@ -52,7 +52,7 @@ uint8_t MarlinHAL::active_ch = 0;
|
||||
|
||||
uint16_t MarlinHAL::adc_value() {
|
||||
const pin_t pin = analogInputToDigitalPin(active_ch);
|
||||
if (!VALID_PIN(pin)) return 0;
|
||||
if (!isValidPin(pin)) return 0;
|
||||
return uint16_t((Gpio::get(pin) >> 2) & 0x3FF); // return 10bit value as Marlin expects
|
||||
}
|
||||
|
||||
|
||||
@@ -49,28 +49,28 @@ extern "C" void delay(const int msec) {
|
||||
// IO functions
|
||||
// As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
|
||||
void pinMode(const pin_t pin, const uint8_t mode) {
|
||||
if (!VALID_PIN(pin)) return;
|
||||
if (!isValidPin(pin)) return;
|
||||
Gpio::setMode(pin, mode);
|
||||
}
|
||||
|
||||
void digitalWrite(pin_t pin, uint8_t pin_status) {
|
||||
if (!VALID_PIN(pin)) return;
|
||||
if (!isValidPin(pin)) return;
|
||||
Gpio::set(pin, pin_status);
|
||||
}
|
||||
|
||||
bool digitalRead(pin_t pin) {
|
||||
if (!VALID_PIN(pin)) return false;
|
||||
if (!isValidPin(pin)) return false;
|
||||
return Gpio::get(pin);
|
||||
}
|
||||
|
||||
void analogWrite(pin_t pin, int pwm_value) { // 1 - 254: pwm_value, 0: LOW, 255: HIGH
|
||||
if (!VALID_PIN(pin)) return;
|
||||
if (!isValidPin(pin)) return;
|
||||
Gpio::set(pin, pwm_value);
|
||||
}
|
||||
|
||||
uint16_t analogRead(pin_t adc_pin) {
|
||||
if (!VALID_PIN(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin))) return 0;
|
||||
return Gpio::get(DIGITAL_PIN_TO_ANALOG_PIN(adc_pin));
|
||||
if (!isValidPin(digitalPinToAnalogIndex(adc_pin))) return 0;
|
||||
return Gpio::get(digitalPinToAnalogIndex(adc_pin));
|
||||
}
|
||||
|
||||
char *dtostrf(double __val, signed char __width, unsigned char __prec, char *__s) {
|
||||
|
||||
@@ -137,12 +137,12 @@ extern DefaultSerial1 USBSerial;
|
||||
//
|
||||
|
||||
// Test whether the pin is valid
|
||||
constexpr bool VALID_PIN(const pin_t pin) {
|
||||
constexpr bool isValidPin(const pin_t pin) {
|
||||
return LPC176x::pin_is_valid(pin);
|
||||
}
|
||||
|
||||
// Get the analog index for a digital pin
|
||||
constexpr int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t pin) {
|
||||
constexpr int8_t digitalPinToAnalogIndex(const pin_t pin) {
|
||||
return (LPC176x::pin_is_valid(pin) && LPC176x::pin_has_adc(pin)) ? pin : -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user