Clean up HALs / FastIO (#14082)

This commit is contained in:
Giuliano Zaro 2019-05-22 01:28:12 +02:00 committed by Scott Lahteine
parent 4ef364a073
commit a74aad3b4a
21 changed files with 17 additions and 187 deletions

View File

@ -83,7 +83,6 @@
#define _IS_INPUT(IO) !TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _IS_OUTPUT(IO) TEST(DIO ## IO ## _DDR, DIO ## IO ## _PIN)
#define _HAS_TIMER(IO) bool(DIO ## IO ## _PWM)
// digitalRead/Write wrappers
#ifdef FASTIO_EXT_START
@ -106,7 +105,6 @@
#define IS_INPUT(IO) _IS_INPUT(IO)
#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
#define HAS_TIMER(IO) _HAS_TIMER(IO)
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
@ -353,5 +351,3 @@ enum ClockSource2 : char {
#else
#error "unknown CPU"
#endif
#define USEABLE_HARDWARE_PWM(P) (PWM_PIN(P) && !PWM_CHK(P))

View File

@ -78,14 +78,6 @@
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
typedef int8_t pin_t;
#define HAL_SERVO_LIB Servo
@ -143,13 +135,6 @@ inline void HAL_adc_init(void) {}//todo
void HAL_adc_start_conversion(const uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
//
// Pin Map

View File

@ -46,7 +46,6 @@
// Due has 12 PWMs assigned to logical pins 2-13.
// 6, 7, 8 & 9 come from the PWM controller. The others come from the timers.
#define PWM_PIN(P) WITHIN(P, 2, 13)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#ifndef MASK
#define MASK(PIN) (1 << PIN)
@ -180,8 +179,6 @@
#define IS_INPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) == 0)
// Check if pin is an output
#define IS_OUTPUT(IO) ((digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO)) != 0)
// Check if pin is a timer - Must be a constexpr
#define HAS_TIMER(IO) ((IO) >= 2 && (IO) <= 13)
// Shorthand
#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }

View File

@ -67,7 +67,6 @@
// PWM outputs
#define PWM_PIN(P) (P < 34) // NOTE Pins >= 34 are input only on ESP32, so they can't be used for output.
#define USEABLE_HARDWARE_PWM(P) (!IS_I2S_EXPANDER_PIN(P) && PWM_PIN(P))
// Toggle pin value
#define TOGGLE(IO) WRITE(IO, !READ(IO))

View File

@ -80,16 +80,6 @@
/// check if pin is an output
#define _IS_OUTPUT(IO) (LPC1768_PIN_PIN(IO) >= 0)
// hg42: HAS_TIMER is used only to check if it's a PWM pin
// hg42: we cannot use USEABLE_HARDWARE_PWM because it uses a function that cannot be used statically
// hg42: instead use PWM bit from the #define
/// check if pin is a timer
#define _HAS_TIMER(IO) true // could be LPC1768_PIN_PWM(IO), but there
// hg42: could be this:
// #define _HAS_TIMER(IO) LPC1768_PIN_PWM(IO)
// but this is an incomplete check (12 pins are PWMable, but only 6 can be used at the same time)
/// Read a pin wrapper
#define READ(IO) _READ(IO)
@ -116,14 +106,9 @@
/// check if pin is an output wrapper
#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
/// check if pin is a timer (wrapper)
#define HAS_TIMER(IO) _HAS_TIMER(IO)
// Shorthand
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)

View File

@ -21,11 +21,6 @@
*/
#pragma once
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define WDT_TIMEOUT 4000000 // 4 second timeout
void watchdog_init(void);

View File

@ -36,7 +36,6 @@
#include "../shared/Marduino.h"
#define PWM_PIN(P) true // all pins are PWM capable
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#define LPC_PIN(pin) gpio_pin(pin)
#define LPC_GPIO(port) gpio_port(port)
@ -89,10 +88,6 @@
/// check if pin is an output
#define _IS_OUTPUT(IO) (gpio_get_dir(IO))
/// check if pin is a timer
/// all gpio pins are pwm capable, either interrupt or hardware pwm controlled
#define _HAS_TIMER(IO) true
/// Read a pin wrapper
#define READ(IO) _READ(IO)
@ -119,9 +114,6 @@
/// check if pin is an output wrapper
#define IS_OUTPUT(IO) _IS_OUTPUT(IO)
/// check if pin is a timer (wrapper)
#define HAS_TIMER(IO) _HAS_TIMER(IO)
// Shorthand
#define OUT_WRITE(IO,V) do{ SET_OUTPUT(IO); WRITE(IO,V); }while(0)

View File

@ -21,11 +21,6 @@
*/
#pragma once
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define WDT_TIMEOUT 4000000 // 4 second timeout
void watchdog_init(void);

View File

@ -127,14 +127,6 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
// --------------------------------------------------------------------------
// Types
// --------------------------------------------------------------------------

View File

@ -80,10 +80,8 @@ void FastIO_init(); // Must be called before using fast io macros
#define IS_INPUT(IO)
#define IS_OUTPUT(IO)
#define HAS_TIMER(IO) digitalPinHasPWM(IO)
#define PWM_PIN(P) HAS_TIMER(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#define PWM_PIN(P) digitalPinHasPWM(P)
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)

View File

@ -253,23 +253,8 @@ void HAL_adc_init(void);
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/* Todo: Confirm none of this is needed.
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

View File

@ -50,10 +50,8 @@
#define IS_INPUT(IO) (_GET_MODE(IO) == GPIO_INPUT_FLOATING || _GET_MODE(IO) == GPIO_INPUT_ANALOG || _GET_MODE(IO) == GPIO_INPUT_PU || _GET_MODE(IO) == GPIO_INPUT_PD)
#define IS_OUTPUT(IO) (_GET_MODE(IO) == GPIO_OUTPUT_PP)
#define HAS_TIMER(IO) (PIN_MAP[IO].timer_device != nullptr)
#define PWM_PIN(P) HAS_TIMER(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#define PWM_PIN(P) (PIN_MAP[IO].timer_device != nullptr)
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)

View File

@ -136,14 +136,6 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
// --------------------------------------------------------------------------
// Types
// --------------------------------------------------------------------------
@ -232,23 +224,8 @@ inline void HAL_adc_init(void) {}
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/* Todo: Confirm none of this is needed.
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

View File

@ -50,10 +50,8 @@
#define IS_INPUT(IO)
#define IS_OUTPUT(IO)
#define HAS_TIMER(IO) true
#define PWM_PIN(P) HAS_TIMER(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#define PWM_PIN(P) true
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)

View File

@ -125,14 +125,6 @@
#undef pgm_read_ptr
#define pgm_read_ptr(addr) (*(addr))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
// --------------------------------------------------------------------------
// Types
// --------------------------------------------------------------------------
@ -211,23 +203,8 @@ inline void HAL_adc_init(void) {}
#define HAL_ADC_READY() true
void HAL_adc_start_conversion(const uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/* Todo: Confirm none of this is needed.
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

View File

@ -49,10 +49,8 @@
#define IS_INPUT(IO)
#define IS_OUTPUT(IO)
#define HAS_TIMER(IO) true
#define PWM_PIN(P) HAS_TIMER(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
#define PWM_PIN(P) true
// digitalRead/Write wrappers
#define extDigitalRead(IO) digitalRead(IO)

View File

@ -89,14 +89,6 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
// Clear the reset reason
void HAL_clear_reset_source(void);
@ -128,25 +120,11 @@ void HAL_adc_init();
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
#define HAL_ANALOG_SELECT(pin) NOOP;
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_start_conversion(const uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/*
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

View File

@ -91,7 +91,6 @@
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define PWM_PIN(P) digitalPinHasPWM(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
/**
* Ports, functions, and pins

View File

@ -97,14 +97,6 @@ typedef int8_t pin_t;
#undef pgm_read_word
#define pgm_read_word(addr) (*((uint16_t*)(addr)))
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64
/** clear reset reason */
void HAL_clear_reset_source(void);
@ -133,25 +125,11 @@ void HAL_adc_init();
#define HAL_READ_ADC() HAL_adc_get_result()
#define HAL_ADC_READY() true
#define HAL_ANALOG_SELECT(pin) NOOP;
#define HAL_ANALOG_SELECT(pin)
void HAL_adc_start_conversion(const uint8_t adc_pin);
uint16_t HAL_adc_get_result(void);
/*
uint16_t HAL_getAdcReading(uint8_t chan);
void HAL_startAdcConversion(uint8_t chan);
uint8_t HAL_pinToAdcChannel(int pin);
uint16_t HAL_getAdcFreerun(uint8_t chan, bool wait_for_conversion = false);
//uint16_t HAL_getAdcSuperSample(uint8_t chan);
void HAL_enable_AdcFreerun(void);
//void HAL_disable_AdcFreerun(uint8_t chan);
*/
#define GET_PIN_MAP_PIN(index) index
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

View File

@ -90,7 +90,6 @@
#define extDigitalWrite(IO,V) digitalWrite(IO,V)
#define PWM_PIN(P) digitalPinHasPWM(P)
#define USEABLE_HARDWARE_PWM(P) PWM_PIN(P)
/**
* Ports, functions, and pins

View File

@ -55,3 +55,12 @@
//#define strchr_P(s,c) strchr(s,c)
#endif
#endif
// Restart causes
#define RST_POWER_ON 1
#define RST_EXTERNAL 2
#define RST_BROWN_OUT 4
#define RST_WATCHDOG 8
#define RST_JTAG 16
#define RST_SOFTWARE 32
#define RST_BACKUP 64