Use registers to bling the relays
This commit is contained in:
parent
5ddd8ef236
commit
55ffaf10fa
|
@ -59,21 +59,25 @@ int main(void) {
|
||||||
|
|
||||||
MOD_IO2::Setup();
|
MOD_IO2::Setup();
|
||||||
|
|
||||||
bool should_blink = false;
|
bool should_blink = true;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
Wait_Ms(1000);
|
Wait_Ms(1000);
|
||||||
|
|
||||||
printf("-DEBUG-PR-%08x\r\n", i++);
|
printf("-DEBUG-PR-%08x\r\n", i++);
|
||||||
if(should_blink) {
|
if(should_blink) {
|
||||||
MOD_IO2::onRelayOn(0x40, 0, 0x03);
|
MOD_IO2::onRegisterSet(0x41);
|
||||||
|
MOD_IO2::onRegWrite(0x41, 0, 3);
|
||||||
|
// MOD_IO2::onRelayOn(0x40, 0, 0x03);
|
||||||
}
|
}
|
||||||
Wait_Ms(1000);
|
Wait_Ms(1000);
|
||||||
|
|
||||||
printf("-DEBUG-PR-%08x\r\n", i++);
|
printf("-DEBUG-PR-%08x\r\n", i++);
|
||||||
if(should_blink) {
|
if(should_blink) {
|
||||||
MOD_IO2::onRelayOff(0x40, 0, 0x03);
|
MOD_IO2::onRegisterSet(0x42);
|
||||||
|
MOD_IO2::onRegWrite(0x41, 0, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "mod_io2.h"
|
#include "mod_io2.h"
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
// Disable LOG_DEBUG locally
|
// Disable LOG_DEBUG locally
|
||||||
#undef LOD_DEBUG_ENABLE
|
#undef LOD_DEBUG_ENABLE
|
||||||
|
@ -223,6 +224,7 @@ void MOD_IO2::onRelayOn(uint8_t reg, uint8_t offset, uint8_t data) {
|
||||||
RelaySet(relay, Bit_SET);
|
RelaySet(relay, Bit_SET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printf("RelaysOn, reg: %d, offset: %d, data: %d\r\n", reg, offset, data);
|
||||||
LOG_DEBUG("RelaysOn " BYTE_TO_BINARY_PATTERN EOL, BYTE_TO_BINARY(relay_state));
|
LOG_DEBUG("RelaysOn " BYTE_TO_BINARY_PATTERN EOL, BYTE_TO_BINARY(relay_state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,12 +95,43 @@ protected:
|
||||||
static uint8_t onGetRelayState(uint8_t reg, uint8_t offset);
|
static uint8_t onGetRelayState(uint8_t reg, uint8_t offset);
|
||||||
static void onSetRelayState(uint8_t reg, uint8_t offset, uint8_t data);
|
static void onSetRelayState(uint8_t reg, uint8_t offset, uint8_t data);
|
||||||
|
|
||||||
|
static void onRelayOn(uint8_t reg, uint8_t offset, uint8_t data);
|
||||||
|
static void onRelayOff(uint8_t reg, uint8_t offset, uint8_t data);
|
||||||
static uint8_t onGetRelayOff(uint8_t reg, uint8_t offset);
|
static uint8_t onGetRelayOff(uint8_t reg, uint8_t offset);
|
||||||
|
|
||||||
static void onSetPWM(uint8_t reg, uint8_t offset, uint8_t data);
|
static void onSetPWM(uint8_t reg, uint8_t offset, uint8_t data);
|
||||||
|
|
||||||
static void onSetAddress(uint8_t reg, uint8_t offset, uint8_t data);
|
static void onSetAddress(uint8_t reg, uint8_t offset, uint8_t data);
|
||||||
|
|
||||||
|
inline static const MOD_IO2_REG_Map_Type REG_MAP[MOD_IO2_REG_COUNT] = {
|
||||||
|
{.reg = MOD_IO2_SET_DIR, .onRead = onGetDir, .onWrite = onSetDir},
|
||||||
|
{.reg = MOD_IO2_SET_OUT, .onRead = onGetLevel, .onWrite = onSetLevel},
|
||||||
|
{.reg = MOD_IO2_GET_IN, .onRead = onGetLevel, .onWrite = NULL},
|
||||||
|
{.reg = MOD_IO2_SET_PULL_UP, .onRead = onGetPullUp, .onWrite = onSetPullUp},
|
||||||
|
|
||||||
|
// Analog input
|
||||||
|
{.reg = MOD_IO2_GET_ANALOG0, .onRead = onAnalogGet, .onWrite = NULL},
|
||||||
|
{.reg = MOD_IO2_GET_ANALOG5, .onRead = onAnalogGet, .onWrite = NULL},
|
||||||
|
{.reg = MOD_IO2_GET_ANALOG6, .onRead = onAnalogGet, .onWrite = NULL},
|
||||||
|
|
||||||
|
{.reg = MOD_IO2_GET_BOARD_ID, .onRead = onGetBoardID, .onWrite = NULL},
|
||||||
|
{.reg = MOD_IO2_GET_VERSION, .onRead = onGetVersion, .onWrite = NULL},
|
||||||
|
|
||||||
|
{.reg = MOD_IO2_RELAY_STATE, .onRead = onGetRelayState, .onWrite = onSetRelayState},
|
||||||
|
{.reg = MOD_IO2_RELAY_ON, .onRead = onGetRelayState, .onWrite = onRelayOn},
|
||||||
|
{.reg = MOD_IO2_RELAY_OFF, .onRead = onGetRelayOff, .onWrite = onRelayOff},
|
||||||
|
{.reg = MOD_IO2_RELAY_STATE_GET, .onRead = onGetRelayState, .onWrite = NULL},
|
||||||
|
|
||||||
|
// PWM
|
||||||
|
{.reg = MOD_IO2_SET_PWM_OFF, .onRead = NULL, .onWrite = onSetPWM},
|
||||||
|
{.reg = MOD_IO2_SET_PWM1, .onRead = NULL, .onWrite = onSetPWM},
|
||||||
|
{.reg = MOD_IO2_SET_PWM2, .onRead = NULL, .onWrite = onSetPWM},
|
||||||
|
|
||||||
|
// DAC is NOT available
|
||||||
|
{.reg = 0x60, .onRead = NULL, .onWrite = NULL},
|
||||||
|
|
||||||
|
{.reg = MOD_IO2_SET_ADDRESS, .onRead = NULL, .onWrite = onSetAddress},
|
||||||
|
};
|
||||||
|
|
||||||
inline static const MOD_IO2_GPIO_Map_Type PGM1_JUMPER = {
|
inline static const MOD_IO2_GPIO_Map_Type PGM1_JUMPER = {
|
||||||
.port = GPIOD, .pin = GPIO_Pin_1, .adc = 255, .tim = NULL, .tch = 255
|
.port = GPIOD, .pin = GPIO_Pin_1, .adc = 255, .tim = NULL, .tch = 255
|
||||||
|
@ -172,40 +203,6 @@ public:
|
||||||
static void onRegisterSet(uint8_t reg);
|
static void onRegisterSet(uint8_t reg);
|
||||||
static uint8_t onRegRead(uint8_t reg, uint8_t offset);
|
static uint8_t onRegRead(uint8_t reg, uint8_t offset);
|
||||||
static void onRegWrite(uint8_t reg, uint8_t offset, uint8_t data);
|
static void onRegWrite(uint8_t reg, uint8_t offset, uint8_t data);
|
||||||
static void onRelayOn(uint8_t reg, uint8_t offset, uint8_t data);
|
|
||||||
static void onRelayOff(uint8_t reg, uint8_t offset, uint8_t data);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
inline static const MOD_IO2_REG_Map_Type REG_MAP[MOD_IO2_REG_COUNT] = {
|
|
||||||
{.reg = MOD_IO2_SET_DIR, .onRead = onGetDir, .onWrite = onSetDir},
|
|
||||||
{.reg = MOD_IO2_SET_OUT, .onRead = onGetLevel, .onWrite = onSetLevel},
|
|
||||||
{.reg = MOD_IO2_GET_IN, .onRead = onGetLevel, .onWrite = NULL},
|
|
||||||
{.reg = MOD_IO2_SET_PULL_UP, .onRead = onGetPullUp, .onWrite = onSetPullUp},
|
|
||||||
|
|
||||||
// Analog input
|
|
||||||
{.reg = MOD_IO2_GET_ANALOG0, .onRead = onAnalogGet, .onWrite = NULL},
|
|
||||||
{.reg = MOD_IO2_GET_ANALOG5, .onRead = onAnalogGet, .onWrite = NULL},
|
|
||||||
{.reg = MOD_IO2_GET_ANALOG6, .onRead = onAnalogGet, .onWrite = NULL},
|
|
||||||
|
|
||||||
{.reg = MOD_IO2_GET_BOARD_ID, .onRead = onGetBoardID, .onWrite = NULL},
|
|
||||||
{.reg = MOD_IO2_GET_VERSION, .onRead = onGetVersion, .onWrite = NULL},
|
|
||||||
|
|
||||||
{.reg = MOD_IO2_RELAY_STATE, .onRead = onGetRelayState, .onWrite = onSetRelayState},
|
|
||||||
{.reg = MOD_IO2_RELAY_ON, .onRead = onGetRelayState, .onWrite = onRelayOn},
|
|
||||||
{.reg = MOD_IO2_RELAY_OFF, .onRead = onGetRelayOff, .onWrite = onRelayOff},
|
|
||||||
{.reg = MOD_IO2_RELAY_STATE_GET, .onRead = onGetRelayState, .onWrite = NULL},
|
|
||||||
|
|
||||||
// PWM
|
|
||||||
{.reg = MOD_IO2_SET_PWM_OFF, .onRead = NULL, .onWrite = onSetPWM},
|
|
||||||
{.reg = MOD_IO2_SET_PWM1, .onRead = NULL, .onWrite = onSetPWM},
|
|
||||||
{.reg = MOD_IO2_SET_PWM2, .onRead = NULL, .onWrite = onSetPWM},
|
|
||||||
|
|
||||||
// DAC is NOT available
|
|
||||||
{.reg = 0x60, .onRead = NULL, .onWrite = NULL},
|
|
||||||
|
|
||||||
{.reg = MOD_IO2_SET_ADDRESS, .onRead = NULL, .onWrite = onSetAddress},
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __MOD_IO2_H */
|
#endif /* __MOD_IO2_H */
|
||||||
|
|
Loading…
Reference in a new issue