I2Cwrapper v0.5.0
Generic framework for Arduino I2C target devices
|
Generic firmware framework for I2C targets with modular functionality, built around the I2Cwrapper library. More...
Generic firmware framework for I2C targets with modular functionality, built around the I2Cwrapper library.
Copyright (c) 2022 juh
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
make I2C address configurable by hardware (with module?)
return messages (results) should ideally come with an id, too, so that controller can be sure it's the correct result. Currently only CRC8, i.e. correct transmission is checked.
volatile variables / ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {}
Reduce memory use to make it fit into an 8k Attiny4k ATtiny
Macros | |
#define | MF_STAGE_includes 1 |
#define | MF_STAGE_declarations 2 |
#define | MF_STAGE_setup 3 |
#define | MF_STAGE_loop 4 |
#define | MF_STAGE_processMessage 5 |
#define | MF_STAGE_reset 6 |
#define | MF_STAGE_receiveEvent 7 |
#define | MF_STAGE_requestEvent 8 |
#define | MF_STAGE_I2CstateChange 9 |
#define | MF_STAGE MF_STAGE_includes |
#define | log(...) |
#define | MF_STAGE MF_STAGE_I2CstateChange |
#define | MF_STAGE MF_STAGE_declarations |
#define | MF_STAGE MF_STAGE_setup |
#define | MF_STAGE MF_STAGE_loop |
#define | MF_STAGE MF_STAGE_processMessage |
#define | MF_STAGE MF_STAGE_reset |
#define | MF_STAGE MF_STAGE_receiveEvent |
#define | MF_STAGE MF_STAGE_requestEvent |
Enumerations | |
enum | I2Cstates { initializing , readyForCommand , processingCommand , readyForResponse , responding , tainted } |
Functions | |
void | changeI2CstateTo (I2Cstates newState) |
void | receiveEvent (int howMany) |
void | requestEvent () |
Handle I2C request event. Will send results or information requested by the last command, as defined by the contents of the outputBuffer. More... | |
void | triggerInterrupt (uint8_t source, uint8_t reason) |
Interrupt controller if an interrupt pin has been set and, optionally, define a source and reason having caused the interrupt that the controller can learn about by calling the I2Cwrapper::clearInterrupt() function. More... | |
void | clearInterrupt () |
void | initializeFirmware () |
void | startI2C () |
void | setup () |
Setup system. More... | |
void | loop () |
Main loop. By default, it doesn't do a lot apart from debugging: It just checks if an ISR signaled that a new message has arrived and calls processMessage() accordingly. More... | |
void | processMessage (uint8_t len) |
Process the message stored in bufferIn with lenght len which was received via I2C. Messages consist of at least three bytes: [0] CRC8 checksum [1] Command. Most commands correspond to a module's function, some are specific for I2Cwrapper core functions. Unknown commands are ignored. [2] Number of the unit (stepper, servo, ...) that is to receive the command. Not all modules use units and ignore this value accordingly. [3..maxBuffer] Optional parameter bytes. Each command that comes with too many or too few parameter bytes is ignored. More... | |
void | writeOutputBuffer () |
Variables | |
uint8_t | i2c_address = I2CwrapperDefaultAddress |
uint32_t | cycles = 0 |
SimpleBuffer * | bufferIn |
SimpleBuffer * | bufferOut |
volatile uint8_t | newMessage = 0 |
volatile I2Cstates | I2Cstate = initializing |
int8_t | interruptPin |
bool | interruptActiveHigh |
uint8_t | interruptSource |
uint8_t | interruptReason |
#define log | ( | ... | ) |
#define MF_STAGE MF_STAGE_includes |
#define MF_STAGE MF_STAGE_I2CstateChange |
#define MF_STAGE MF_STAGE_declarations |
#define MF_STAGE MF_STAGE_setup |
#define MF_STAGE MF_STAGE_loop |
#define MF_STAGE MF_STAGE_processMessage |
#define MF_STAGE MF_STAGE_reset |
#define MF_STAGE MF_STAGE_receiveEvent |
#define MF_STAGE MF_STAGE_requestEvent |
#define MF_STAGE_declarations 2 |
#define MF_STAGE_I2CstateChange 9 |
#define MF_STAGE_includes 1 |
#define MF_STAGE_loop 4 |
#define MF_STAGE_processMessage 5 |
#define MF_STAGE_receiveEvent 7 |
#define MF_STAGE_requestEvent 8 |
#define MF_STAGE_reset 6 |
#define MF_STAGE_setup 3 |
enum I2Cstates |
void changeI2CstateTo | ( | I2Cstates | newState | ) |
void clearInterrupt | ( | ) |
void initializeFirmware | ( | ) |
void loop | ( | void | ) |
Main loop. By default, it doesn't do a lot apart from debugging: It just checks if an ISR signaled that a new message has arrived and calls processMessage() accordingly.
void processMessage | ( | uint8_t | len | ) |
Process the message stored in bufferIn with lenght len which was received via I2C. Messages consist of at least three bytes: [0] CRC8 checksum [1] Command. Most commands correspond to a module's function, some are specific for I2Cwrapper core functions. Unknown commands are ignored. [2] Number of the unit (stepper, servo, ...) that is to receive the command. Not all modules use units and ignore this value accordingly. [3..maxBuffer] Optional parameter bytes. Each command that comes with too many or too few parameter bytes is ignored.
void receiveEvent | ( | int | howMany | ) |
@ brief Handle I2C receive event. Just read the message and inform main loop.
void requestEvent | ( | ) |
Handle I2C request event. Will send results or information requested by the last command, as defined by the contents of the outputBuffer.
void setup | ( | void | ) |
Setup system.
void startI2C | ( | ) |
void triggerInterrupt | ( | uint8_t | source, |
uint8_t | reason | ||
) |
Interrupt controller if an interrupt pin has been set and, optionally, define a source and reason having caused the interrupt that the controller can learn about by calling the I2Cwrapper::clearInterrupt() function.
source | 4-bit value that can be used to signal the controller where in the target device the interrupt occured, e.g. which end stop switch was triggered or which touch button was touched. 0xF is reserved to signal "unknown source" |
reason | 4-bit value that can be used to differentiate between different interrupt causing events, e.g. end stop hit vs. target reached. 0xF is reserved to signal "unknown reason" |
void writeOutputBuffer | ( | ) |
SimpleBuffer* bufferIn |
SimpleBuffer* bufferOut |
uint32_t cycles = 0 |
uint8_t i2c_address = I2CwrapperDefaultAddress |
volatile I2Cstates I2Cstate = initializing |
bool interruptActiveHigh |
int8_t interruptPin |
uint8_t interruptReason |
uint8_t interruptSource |
volatile uint8_t newMessage = 0 |