HULP - ULP Helper
Posted: Tue Dec 31, 2019 1:05 pm
https://github.com/boarchuz/HULP
HULP contains a bunch of useful macros and a few functions to more easily program the ULP coprocessor (using legacy macros).
ulp_var_t to easily share data between the SoC and ULP:
I2C bitbang driver supporting multiple slaves, 16 bit reads, error callbacks, etc. All in just 76 instructions. Single-line "include" to add to your ULP program:
Example here:
https://github.com/boarchuz/HULP/blob/r ... d/main.cpp
UART driver supporting TX, RX, and with a simple ulp_string_t to share char arrays between ULP and SoC.
Echo-style example here:
https://github.com/boarchuz/HULP/blob/r ... g/main.cpp
Timing functions and macros to convert transparently between milliseconds and RTC ticks. This allows for much easier timing of tasks, multi-tasking, etc.
To toggle an LED every 1650ms, for example:
Example here: https://github.com/boarchuz/HULP/blob/r ... e/main.cpp
IO Macros:
Single APA RGB LED driver:
Example: https://github.com/boarchuz/HULP/blob/r ... s/main.cpp
Other bits:
HULP contains a bunch of useful macros and a few functions to more easily program the ULP coprocessor (using legacy macros).
ulp_var_t to easily share data between the SoC and ULP:
Code: Select all
RTC_DATA_ATTR ulp_var_t ulp_myvariable;
//ULP
I_GET(R0, R2, ulp_myvariable),
I_ADDI(R0, R0, 1),
I_PUT(R0, R2, ulp_myvariable),
//SoC
ulp_myvariable.put(1234);
if (ulp_myvariable.updated()) {
uint16_t val = ulp_myvariable.get();
}
Code: Select all
M_INCLUDE_I2CBB_MULTI(LBL_I2C_READ_ENTRY, LBL_I2C_WRITE_ENTRY, LBL_I2C_BUS_ERROR_HANDLER, LBL_I2C_NACK_ERROR_HANDLER, SCL_PIN, SDA_PIN),
https://github.com/boarchuz/HULP/blob/r ... d/main.cpp
UART driver supporting TX, RX, and with a simple ulp_string_t to share char arrays between ULP and SoC.
Echo-style example here:
https://github.com/boarchuz/HULP/blob/r ... g/main.cpp
Timing functions and macros to convert transparently between milliseconds and RTC ticks. This allows for much easier timing of tasks, multi-tasking, etc.
To toggle an LED every 1650ms, for example:
Code: Select all
M_UPDATE_TICKS(),
M_IF_MS_ELAPSED(/*Label:*/ LBL_THIS_BLOCK, /*ms:*/ 1650, /*else goto:*/ LBL_HALT),
M_GPIO_TOGGLE(PIN_LED),
M_LABEL(LBL_HALT),
I_HALT(),
IO Macros:
Code: Select all
I_ANALOG_READ(R0, GPIO_NUM_36),
I_GPIO_PULLUP(GPIO_NUM_32, 1),
I_GPIO_READ(GPIO_NUM_32),
I_GPIO_OUTPUT_EN(GPIO_NUM_25),
I_GPIO_SET(GPIO_NUM_25, 1),
I_GPIO_SET(GPIO_NUM_25, 0),
Code: Select all
M_APA1_SET(/*Label:*/ LBL_THIS_BLOCK, /*subroutine entry:*/ LBL_APA_ENTRY, /*brightness:*/ 16, /*red:*/ 255, /*green:*/ 127, /*blue:*/ 63),
M_INCLUDE_APA1(LBL_APA_ENTRY, SCL_PIN, SDA_PIN),
Other bits:
Code: Select all
hulp_configure_pin(GPIO_NUM_2, RTC_GPIO_MODE_INPUT_ONLY);
hulp_configure_i2c_pins(GPIO_NUM_4, GPIO_NUM_15);
hulp_configure_i2c_controller();
M_TOUCH_BEGIN(),
M_TOUCH_WAIT_DONE(),
I_TOUCH_GET_GPIO_VALUE(GPIO_NUM_x),