initial commit
This commit is contained in:
84
io/IO.h
Normal file
84
io/IO.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#ifndef IO_H
|
||||
#define IO_H
|
||||
|
||||
// http://www.electrodragon.com/w/ESP8266_IoT_Firmware
|
||||
// https://esp8266.ru/esp8266-pin-register-strapping/
|
||||
// http://www.limpkin.fr/index.php?post/2014/12/07/First-Steps-with-the-ESP8266-03-Development-Board
|
||||
|
||||
//extern "C" {
|
||||
// #include "eagle_soc.h"
|
||||
// #include "ets_sys.h"
|
||||
//}
|
||||
|
||||
#include "fastGPIO.h"
|
||||
|
||||
class IO {
|
||||
|
||||
public:
|
||||
|
||||
// // https://esp8266.ru/esp8266-pin-register-strapping/
|
||||
// static void setOutput(const uint8_t pin) {
|
||||
// //PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);
|
||||
// //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
|
||||
// }
|
||||
|
||||
// // https://esp8266.ru/esp8266-pin-register-strapping/
|
||||
// static void setInput(const uint8_t pin) {
|
||||
// //PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_U);
|
||||
// //PIN_PULLDWN_DIS(PERIHS_IO_MUX_GPIO0_U);
|
||||
// //PIN_PULLDWN_EN(PERIHS_IO_MUX_GPIO0_U);
|
||||
// }
|
||||
|
||||
__attribute__((always_inline)) static inline void setPinHi(const uint8_t pin) {
|
||||
GPIO_OUTPUT_SET(GPIO_ID_PIN(pin), 1);
|
||||
//gpio_output_set(pin, 0, pin, 0);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void setPinLo(const uint8_t pin) {
|
||||
GPIO_OUTPUT_SET(GPIO_ID_PIN(pin), 0);
|
||||
//gpio_output_set(0, pin, pin, 0);
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline void setPin(const uint8_t pin, const bool val) {
|
||||
GPIO_OUTPUT_SET(GPIO_ID_PIN(pin), val); //val ? 1 : 0;
|
||||
}
|
||||
|
||||
__attribute__((always_inline)) static inline bool getPin(const uint8_t pin) {
|
||||
return GPIO_INPUT_GET(GPIO_ID_PIN(pin));
|
||||
}
|
||||
|
||||
static inline void toggleLED0() {
|
||||
static bool on = false;
|
||||
on = !on;
|
||||
GPIO16_OUTPUT_SET;
|
||||
if (on) {GPIO16_H;} else {GPIO16_L;}
|
||||
}
|
||||
|
||||
static inline void toggleLED1() {
|
||||
static bool on = false;
|
||||
on = !on;
|
||||
GPIO5_OUTPUT_SET;
|
||||
if (on) {GPIO5_H;} else {GPIO5_L;}
|
||||
}
|
||||
|
||||
/** toggle the onboard LED */
|
||||
static inline void toggleBuiltInLED() {
|
||||
static volatile bool on = false;
|
||||
on = !on;
|
||||
|
||||
#if PLATFORM == WEMOS_D1_MINI
|
||||
GPIO2_OUTPUT_SET;
|
||||
if (on) {GPIO2_H;} else {GPIO2_L;}
|
||||
#elif PLATFORM == NODE_MCU
|
||||
GPIO16_OUTPUT_SET;
|
||||
if (on) {GPIO16_H;} else {GPIO16_L;}
|
||||
#else
|
||||
#error "NO PLATFORM"
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // IO_H
|
||||
Reference in New Issue
Block a user