Open FFBoard
Open source force feedback firmware
I2CPort Class Reference

#include <I2C.h>

Inheritance diagram for I2CPort:
I2CHandler CommandHandler PersistentStorage

Public Types

enum class  CanPort_commands : uint32_t { speed }
 

Public Member Functions

 I2CPort (I2C_HandleTypeDef &hi2c, const I2CPortHardwareConfig &presets, uint8_t instance=0)
 
virtual ~I2CPort ()
 
void configurePort (I2C_InitTypeDef *config)
 
void resetPort ()
 
void takePort (I2CDevice *device)
 
void freePort (I2CDevice *device)
 
int32_t getPortUsers ()
 
void setSpeedPreset (uint8_t preset)
 
uint8_t getSpeedPreset ()
 
bool transmitMaster (I2CDevice *device, const uint16_t addr, uint8_t *pData, const uint16_t size, const uint32_t timeout, bool shiftAddr=true)
 
bool transmitMasterDMA (I2CDevice *device, const uint16_t addr, uint8_t *pData, const uint16_t size, bool shiftAddr=true)
 
bool transmitMasterIT (I2CDevice *device, const uint16_t addr, uint8_t *pData, const uint16_t size, bool shiftAddr=true)
 
bool receiveMaster (I2CDevice *device, const uint16_t addr, uint8_t *pData, const uint16_t size, const uint32_t timeout, bool shiftAddr=true)
 
bool receiveMasterDMA (I2CDevice *device, const uint16_t addr, uint8_t *pData, const uint16_t size, bool shiftAddr=true)
 
bool receiveMasterIT (I2CDevice *device, const uint16_t addr, uint8_t *pData, const uint16_t size, bool shiftAddr=true)
 
bool writeMem (I2CDevice *device, const uint16_t devAddr, const uint16_t memAddr, const uint16_t memAddSize, uint8_t *pData, const uint16_t size, const uint32_t timeout, bool shiftAddr=true)
 
bool readMem (I2CDevice *device, const uint16_t devAddr, const uint16_t memAddr, const uint16_t memAddSize, uint8_t *pData, const uint16_t size, const uint32_t timeout, bool shiftAddr=true)
 
bool readMemIT (I2CDevice *device, const uint16_t devAddr, const uint16_t memAddr, const uint16_t memAddSize, uint8_t *pData, const uint16_t size, bool shiftAddr=true)
 
bool writeMemIT (I2CDevice *device, const uint16_t devAddr, const uint16_t memAddr, const uint16_t memAddSize, uint8_t *pData, const uint16_t size, bool shiftAddr=true)
 
bool isDeviceReady (I2CDevice *device, const uint16_t devAddr, const uint32_t trials, uint32_t timeout, bool shiftAddr=true)
 
void takeSemaphore ()
 
void giveSemaphore ()
 
bool isTaken ()
 
void I2cTxCplt (I2C_HandleTypeDef *hi2c)
 
void I2cRxCplt (I2C_HandleTypeDef *hi2c)
 
void I2cError (I2C_HandleTypeDef *hi2c)
 
CommandStatus command (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
void registerCommands ()
 
void saveFlash ()
 
void restoreFlash ()
 
const ClassIdentifier getInfo ()
 Command handlers always have class infos. Works well with ChoosableClass. More...
 
const ClassType getClassType () override
 
- Public Member Functions inherited from I2CHandler
 I2CHandler ()
 
virtual ~I2CHandler ()
 
- Public Member Functions inherited from CommandHandler
 CommandHandler (const char *clsname, uint16_t clsid, uint8_t instance=0)
 
virtual ~CommandHandler ()
 
virtual bool hasCommands ()
 
virtual void setCommandsEnabled (bool enable)
 
void registerCommands ()
 
virtual CommandStatus internalCommand (const ParsedCommand &cmd, std::vector< CommandReply > &replies)
 
virtual std::string getHelpstring ()
 
virtual std::string getCommandsHelpstring ()
 
virtual std::string getCsvHelpstring ()
 
virtual uint8_t getCommandHandlerInstance ()
 
void broadcastCommandReply (CommandReply reply, uint32_t cmdId, CMDtype type)
 
void sendCommandReplyAsync (CommandReply reply, uint32_t cmdId, CMDtype type, CommandInterface *interface=nullptr)
 
virtual uint16_t getCommandHandlerID ()
 
virtual CmdHandlerInfogetCommandHandlerInfo ()
 
virtual bool isValidCommandId (uint32_t cmdid, uint32_t ignoredFlags=0, uint32_t requiredFlag=0)
 
virtual CmdHandlerCommanddefgetCommandFromName (const std::string &cmd, uint32_t ignoredFlags=0)
 
virtual CmdHandlerCommanddefgetCommandFromId (const uint32_t id, uint32_t ignoredFlags=0)
 
template<typename ID >
void registerCommand (const char *cmd, const ID cmdid, const char *help=nullptr, uint32_t flags=0)
 
- Public Member Functions inherited from PersistentStorage
 PersistentStorage ()
 
virtual ~PersistentStorage ()
 
void restoreFlashDelayed ()
 

Static Public Attributes

static ClassIdentifier info
 
- Static Public Attributes inherited from CommandHandler
static bool logEnabled = true
 

Private Types

enum class  I2CPort_commands : uint32_t { speed }
 

Private Attributes

cpp_freertos::BinarySemaphore semaphore = cpp_freertos::BinarySemaphore(true)
 
I2C_HandleTypeDef & hi2c
 
I2CDevicecurrentDevice = nullptr
 
int32_t portUsers = 0
 
uint8_t speedPreset = 0
 
I2C_InitTypeDef config
 
const I2CPortHardwareConfigpresets
 

Additional Inherited Members

- Static Public Member Functions inherited from I2CHandler
static std::vector< I2CHandler * > & getI2CHandlers ()
 
- Static Public Member Functions inherited from CommandHandler
static void logSerial (std::string string)
 Send a log formatted sequence. More...
 
static void logSerialDebug (std::string string)
 Send a log formatted sequence if debug is on. More...
 
static bool logsEnabled ()
 
static void setLogsEnabled (bool enabled)
 
static uint32_t getClassIdFromName (const char *name)
 
static const char * getClassNameFromId (const uint32_t id)
 
static CommandHandlergetHandlerFromHandlerId (const uint16_t cmdhandlerID)
 
static CommandHandlergetHandlerFromId (const uint16_t id, const uint8_t instance=0xFF)
 
static CommandHandlergetHandlerFromClassName (const char *name, const uint8_t instance=0xFF)
 
static std::vector< CommandHandler * > getHandlersFromClassName (const char *name)
 
static std::vector< CommandHandler * > getHandlersFromId (const uint16_t id)
 
static bool isInHandlerList (CommandHandler *handler)
 
static std::string getAllHelpstrings ()
 
static std::vector< CommandHandler * > & getCommandHandlers ()
 
template<typename TVal >
static CommandStatus handleGetSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value)
 
template<typename TVal , class cls , class cls1 >
static CommandStatus handleGetSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, void(cls1::*setfunc)(TVal), cls *obj)
 
template<typename TVal , class cls , class cls1 , class cls2 >
static CommandStatus handleGetFuncSetFunc (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal(cls1::*getfunc)(), void(cls2::*setfunc)(TVal), cls *obj)
 
template<typename TVal , class cls , class cls1 >
static CommandStatus handleGetFuncSet (const ParsedCommand &cmd, std::vector< CommandReply > &replies, TVal &value, TVal(cls1::*getfunc)(), cls *obj)
 
- Static Public Member Functions inherited from PersistentStorage
static std::vector< PersistentStorage * > & getFlashHandlers ()
 
static void restoreFlashStartupCb ()
 
- Protected Member Functions inherited from CommandHandler
void setInstance (uint8_t instance)
 
virtual void addCommandHandler ()
 
virtual void removeCommandHandler ()
 
- Static Protected Member Functions inherited from CommandHandler
static std::vector< uint16_t > & getCommandHandlerIds ()
 
- Protected Attributes inherited from CommandHandler
bool commandsEnabled = true
 
std::vector< CmdHandlerCommanddefregisteredCommands
 
CmdHandlerInfo cmdHandlerInfo
 
- Protected Attributes inherited from PersistentStorage
bool restoreDelayedFlag = false
 
- Static Protected Attributes inherited from PersistentStorage
static bool startupComplete = false
 

Detailed Description

Definition at line 43 of file I2C.h.

Member Enumeration Documentation

◆ CanPort_commands

enum class I2CPort::CanPort_commands : uint32_t
strong
Enumerator
speed 

Definition at line 84 of file I2C.h.

◆ I2CPort_commands

enum class I2CPort::I2CPort_commands : uint32_t
strongprivate
Enumerator
speed 

Definition at line 44 of file I2C.h.

Constructor & Destructor Documentation

◆ I2CPort()

I2CPort::I2CPort ( I2C_HandleTypeDef &  hi2c,
const I2CPortHardwareConfig presets,
uint8_t  instance = 0 
)

Definition at line 35 of file I2C.cpp.

◆ ~I2CPort()

I2CPort::~I2CPort ( )
virtual

Definition at line 43 of file I2C.cpp.

Member Function Documentation

◆ command()

CommandStatus I2CPort::command ( const ParsedCommand cmd,
std::vector< CommandReply > &  replies 
)
virtual
Parameters
[in]cmdThe parsed command to be executed.
[out]repliesA vector to return one or multiple reply objects into. Replies to the interface will be generated based on the reply objects. A string reply may not contain start, end and separation markers: [,],| Other characters are allowed.

Reimplemented from CommandHandler.

Definition at line 83 of file I2C.cpp.

◆ configurePort()

void I2CPort::configurePort ( I2C_InitTypeDef *  config)

Definition at line 150 of file I2C.cpp.

◆ freePort()

void I2CPort::freePort ( I2CDevice device)

Signals that the port is not needed anymore. Decrements the user counter

Definition at line 132 of file I2C.cpp.

◆ getClassType()

const ClassType I2CPort::getClassType ( )
inlineoverridevirtual

Type of this class. Mainclass, motordriver... Should be implemented by the parent class so it is not in the info struct

Reimplemented from CommandHandler.

Definition at line 91 of file I2C.h.

◆ getInfo()

const ClassIdentifier I2CPort::getInfo ( )
inlinevirtual

Command handlers always have class infos. Works well with ChoosableClass.

Implements CommandHandler.

Definition at line 90 of file I2C.h.

◆ getPortUsers()

int32_t I2CPort::getPortUsers ( )
inline

Definition at line 55 of file I2C.h.

◆ getSpeedPreset()

uint8_t I2CPort::getSpeedPreset ( )

Definition at line 74 of file I2C.cpp.

◆ giveSemaphore()

void I2CPort::giveSemaphore ( )

Definition at line 293 of file I2C.cpp.

◆ I2cError()

void I2CPort::I2cError ( I2C_HandleTypeDef *  hi2c)
virtual

Reimplemented from I2CHandler.

Definition at line 268 of file I2C.cpp.

◆ I2cRxCplt()

void I2CPort::I2cRxCplt ( I2C_HandleTypeDef *  hi2c)
virtual

Reimplemented from I2CHandler.

Definition at line 254 of file I2C.cpp.

◆ I2cTxCplt()

void I2CPort::I2cTxCplt ( I2C_HandleTypeDef *  hi2c)
virtual

Reimplemented from I2CHandler.

Definition at line 240 of file I2C.cpp.

◆ isDeviceReady()

bool I2CPort::isDeviceReady ( I2CDevice device,
const uint16_t  devAddr,
const uint32_t  trials,
uint32_t  timeout,
bool  shiftAddr = true 
)

Definition at line 232 of file I2C.cpp.

◆ isTaken()

bool I2CPort::isTaken ( )

Definition at line 276 of file I2C.cpp.

◆ readMem()

bool I2CPort::readMem ( I2CDevice device,
const uint16_t  devAddr,
const uint16_t  memAddr,
const uint16_t  memAddSize,
uint8_t *  pData,
const uint16_t  size,
const uint32_t  timeout,
bool  shiftAddr = true 
)

Definition at line 208 of file I2C.cpp.

◆ readMemIT()

bool I2CPort::readMemIT ( I2CDevice device,
const uint16_t  devAddr,
const uint16_t  memAddr,
const uint16_t  memAddSize,
uint8_t *  pData,
const uint16_t  size,
bool  shiftAddr = true 
)

Definition at line 216 of file I2C.cpp.

◆ receiveMaster()

bool I2CPort::receiveMaster ( I2CDevice device,
const uint16_t  addr,
uint8_t *  pData,
const uint16_t  size,
const uint32_t  timeout,
bool  shiftAddr = true 
)

Definition at line 179 of file I2C.cpp.

◆ receiveMasterDMA()

bool I2CPort::receiveMasterDMA ( I2CDevice device,
const uint16_t  addr,
uint8_t *  pData,
const uint16_t  size,
bool  shiftAddr = true 
)

Definition at line 187 of file I2C.cpp.

◆ receiveMasterIT()

bool I2CPort::receiveMasterIT ( I2CDevice device,
const uint16_t  addr,
uint8_t *  pData,
const uint16_t  size,
bool  shiftAddr = true 
)

Definition at line 193 of file I2C.cpp.

◆ registerCommands()

void I2CPort::registerCommands ( )

Definition at line 78 of file I2C.cpp.

◆ resetPort()

void I2CPort::resetPort ( )

Forces a reinit

Definition at line 108 of file I2C.cpp.

◆ restoreFlash()

void I2CPort::restoreFlash ( )
virtual

Should be implemented to restore settings. This is not automatically called and should be called when appropriate.

Reimplemented from PersistentStorage.

Definition at line 55 of file I2C.cpp.

◆ saveFlash()

void I2CPort::saveFlash ( )
virtual

Called when the user uses the "save" command and presses the save button in the configurator Automatically called by the command parser thread for every class that inherits from PersistentStorage

Reimplemented from PersistentStorage.

Definition at line 47 of file I2C.cpp.

◆ setSpeedPreset()

void I2CPort::setSpeedPreset ( uint8_t  preset)

Definition at line 65 of file I2C.cpp.

◆ takePort()

void I2CPort::takePort ( I2CDevice device)

Signals that this port is being used. Increments the user counter

Definition at line 117 of file I2C.cpp.

◆ takeSemaphore()

void I2CPort::takeSemaphore ( )

Definition at line 280 of file I2C.cpp.

◆ transmitMaster()

bool I2CPort::transmitMaster ( I2CDevice device,
const uint16_t  addr,
uint8_t *  pData,
const uint16_t  size,
const uint32_t  timeout,
bool  shiftAddr = true 
)

Definition at line 159 of file I2C.cpp.

◆ transmitMasterDMA()

bool I2CPort::transmitMasterDMA ( I2CDevice device,
const uint16_t  addr,
uint8_t *  pData,
const uint16_t  size,
bool  shiftAddr = true 
)

Definition at line 167 of file I2C.cpp.

◆ transmitMasterIT()

bool I2CPort::transmitMasterIT ( I2CDevice device,
const uint16_t  addr,
uint8_t *  pData,
const uint16_t  size,
bool  shiftAddr = true 
)

Definition at line 173 of file I2C.cpp.

◆ writeMem()

bool I2CPort::writeMem ( I2CDevice device,
const uint16_t  devAddr,
const uint16_t  memAddr,
const uint16_t  memAddSize,
uint8_t *  pData,
const uint16_t  size,
const uint32_t  timeout,
bool  shiftAddr = true 
)

Definition at line 200 of file I2C.cpp.

◆ writeMemIT()

bool I2CPort::writeMemIT ( I2CDevice device,
const uint16_t  devAddr,
const uint16_t  memAddr,
const uint16_t  memAddSize,
uint8_t *  pData,
const uint16_t  size,
bool  shiftAddr = true 
)

Definition at line 224 of file I2C.cpp.

Member Data Documentation

◆ config

I2C_InitTypeDef I2CPort::config
private

Definition at line 101 of file I2C.h.

◆ currentDevice

I2CDevice* I2CPort::currentDevice = nullptr
private

Definition at line 98 of file I2C.h.

◆ hi2c

I2C_HandleTypeDef& I2CPort::hi2c
private

Definition at line 97 of file I2C.h.

◆ info

ClassIdentifier I2CPort::info
static
Initial value:
= {
.name = "I2C port",
.id = CLSID_I2CPORT,
.visibility = ClassVisibility::visible}

Definition at line 89 of file I2C.h.

◆ portUsers

int32_t I2CPort::portUsers = 0
private

Definition at line 99 of file I2C.h.

◆ presets

const I2CPortHardwareConfig& I2CPort::presets
private

Definition at line 102 of file I2C.h.

◆ semaphore

Definition at line 95 of file I2C.h.

◆ speedPreset

uint8_t I2CPort::speedPreset = 0
private

Definition at line 100 of file I2C.h.


The documentation for this class was generated from the following files: