All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexime.h File Reference

IME driver macros and prototypes. More...

Go to the source code of this file.

Data Structures

struct  _imeData
 structure to hold everything for one encoder More...
 
struct  _vexImeData
 structure holding all IME data More...
 

Macros

#define IME_MAX   kImeTotal
 Maximum number of IMEs we search for. More...
 
#define DEFAULT_DEVICE   0x60
 Default IME address. More...
 
#define IME_START_ADDRESS   0x20
 Start address when reassigning. More...
 
#define IME_VERSION_ADDR   0x00
 Version request. More...
 
#define IME_VENDOR_ADDR   0x08
 Vendor request. More...
 
#define IME_DEVICEID_ADDR   0x10
 Device ID request. More...
 
#define IME_STATUS_ADDR   0x20
 Status command. More...
 
#define IME_DATA_ADDR   0x40
 Get data command. More...
 
#define IME_SCRATCHR_ADDR   0x60
 read register offset of scratchpad regs More...
 
#define IME_SCRATCHW_ADDR   0xA0
 write register offset of scratchpad regs More...
 
#define IME_CLEAR_COUNTERS   0x4A
 Clear counters command. More...
 
#define IME_DISABLE_TERM   0x4B
 disable termination command More...
 
#define IME_ENABLE_TERM   0x4C
 enable termination command More...
 
#define IME_SETDEV_REG   0x4D
 Set device address command. More...
 
#define IME_RESET_REG   0x4E
 Reset command. More...
 
#define IME_BUF_LEN   16
 
#define ACTION_POLL   0
 
#define ACTION_RENEGOTIATE   1
 
#define IME_COUNT_RESET   0x7F000000
 Dummy value used during IME reset. More...
 
IME motor types
#define IME_269   0
 
#define IME_393T   1
 
#define IME_393S   2
 
#define IME_UND   16
 

Typedefs

typedef struct _imeData imeData
 structure to hold everything for one encoder More...
 
typedef struct _vexImeData vexImeData
 structure holding all IME data More...
 

Enumerations

enum  tVexImeChannels {
  kImeChannel_1 = 0, kImeChannel_2 = 1, kImeChannel_3 = 2, kImeChannel_4 = 3,
  kImeChannel_5 = 4, kImeChannel_6 = 5, kImeChannel_7 = 6, kImeChannel_8 = 7,
  kImeTotal, kImeChannelNone = 99
}
 IME channel definitions. More...
 

Functions

int32_t vexImeGetCount (int16_t channel)
 return encoder count More...
 
void vexImeSetCount (int16_t channel, int32_t value)
 sets encoder count (stores an offset) More...
 
int16_t vexImeGetId (int16_t channel)
 return encoder id More...
 
int16_t vexImeGetChannelMax (void)
 Get the number of IMEs found. More...
 
imeDatavexImeGetPtr (tVexImeChannels channel)
 return pointer to IME data structure More...
 
void vexImeInit (I2CDriver *i2cp, vexStream *chp)
 Initialize IMEs on the I2C bus. More...
 
void vexImeSetType (tVexImeChannels channel, tVexMotorType type)
 Set motor type that this IME is attached to. More...
 
void vexImeSetMotor (tVexImeChannels channel, tVexMotor motor)
 Set the motor that this IME is attached to. More...
 
int32_t vexImeMotorGetCount (tVexMotor motor)
 return encoder count based on motor index More...
 
uint16_t vexIMEFindEncoders (void)
 Search bus and add all encoders found (up to 8) More...
 
void vexIMEDataInit (imeData *ime)
 Init data structure for one IME. More...
 
msg_t vexIMEUpdateCounts (imeData *ime)
 Read encoder data and then calculate the rpm. More...
 
msg_t vexIMEGetVersion (uint8_t device, uint8_t *buf)
 Read version from IME. More...
 
msg_t vexIMEGetVendor (uint8_t device, uint8_t *buf)
 Read vendor from IME. More...
 
msg_t vexIMEGetDeviceId (uint8_t device, uint8_t *buf)
 Read device ID from IME. More...
 
msg_t vexIMEGetStatus (uint8_t device, uint8_t *buf)
 Read Status from IME. More...
 
msg_t vexIMEGetData (uint8_t device, uint8_t *buf)
 Read encoder data from IME. More...
 
msg_t vexIMEGetScratchpad (uint8_t device, uint8_t *buf, uint8_t offset, uint8_t len)
 Read scratchpad data from IME. More...
 
msg_t vexIMESetScratchpad (uint8_t device, uint8_t *buf, uint8_t offset, uint8_t len)
 Write scratchpad data to the IME. More...
 
msg_t vexIMEClearCounters (uint8_t device)
 Clear Counters in IME. More...
 
msg_t vexIMEDisableTermination (uint8_t device)
 Disable termination in IME. More...
 
msg_t vexIMEEnableTermination (uint8_t device)
 Enable termination in IME. More...
 
msg_t vexIMESetAddr (uint8_t *device, uint8_t newDevice)
 
msg_t vexIMEResetAll (void)
 Reset an IME. More...
 
void vexIMEHandleErrors (msg_t status, i2cflags_t errors)
 Handle received IME I2C errors. More...
 
void vexIMEPrintBuf (vexStream *chp, uint8_t *buf, uint8_t len)
 Print a buffer with IME data. More...
 
void vexIMEDebug (vexStream *chp, int argc, char *argv[])
 Debug function to dump IME buffers. More...
 

Detailed Description

IME driver macros and prototypes.

Macro Definition Documentation

#define IME_MAX   kImeTotal

Maximum number of IMEs we search for.

#define DEFAULT_DEVICE   0x60

Default IME address.

#define IME_START_ADDRESS   0x20

Start address when reassigning.

#define IME_VERSION_ADDR   0x00

Version request.

#define IME_VENDOR_ADDR   0x08

Vendor request.

#define IME_DEVICEID_ADDR   0x10

Device ID request.

#define IME_STATUS_ADDR   0x20

Status command.

#define IME_DATA_ADDR   0x40

Get data command.

#define IME_SCRATCHR_ADDR   0x60

read register offset of scratchpad regs

#define IME_SCRATCHW_ADDR   0xA0

write register offset of scratchpad regs

#define IME_CLEAR_COUNTERS   0x4A

Clear counters command.

#define IME_DISABLE_TERM   0x4B

disable termination command

#define IME_ENABLE_TERM   0x4C

enable termination command

#define IME_SETDEV_REG   0x4D

Set device address command.

#define IME_RESET_REG   0x4E

Reset command.

#define IME_BUF_LEN   16
#define ACTION_POLL   0
#define ACTION_RENEGOTIATE   1
#define IME_COUNT_RESET   0x7F000000

Dummy value used during IME reset.

#define IME_269   0
#define IME_393T   1
#define IME_393S   2
#define IME_UND   16

Typedef Documentation

typedef struct _imeData imeData

structure to hold everything for one encoder

typedef struct _vexImeData vexImeData

structure holding all IME data

Enumeration Type Documentation

IME channel definitions.

Enumerator
kImeChannel_1 
kImeChannel_2 
kImeChannel_3 
kImeChannel_4 
kImeChannel_5 
kImeChannel_6 
kImeChannel_7 
kImeChannel_8 
kImeTotal 
kImeChannelNone 

Function Documentation

int32_t vexImeGetCount ( int16_t  channel)

return encoder count

Parameters
[in]channelThe encoder channel
Returns
The encoder count - the offset
Note
channel is int16_t to allow this function to be used in callbacks
void vexImeSetCount ( int16_t  channel,
int32_t  value 
)

sets encoder count (stores an offset)

Parameters
[in]channelThe encoder channel
[in]valueThe new encoder count value
Note
channel is int16_t to allow this function to be used in callbacks
int16_t vexImeGetId ( int16_t  channel)

return encoder id

Parameters
[in]channelThe encoder channel
Returns
The channel id (address) for this channel
int16_t vexImeGetChannelMax ( void  )

Get the number of IMEs found.

Returns
The number of IMEs that were found during the last init
imeData* vexImeGetPtr ( tVexImeChannels  channel)

return pointer to IME data structure

Parameters
[in]channelThe encoder channel
Returns
A pointer to an imeData structure
void vexImeInit ( I2CDriver *  i2cp,
vexStream chp 
)

Initialize IMEs on the I2C bus.

Parameters
[in]i2cpA pointer to the I2C driver (chibios hal driver)
[in]chpA pointer to a vexStream object (used for debug output)
Precondition
The I2C driver should have already been initialized
void vexImeSetType ( tVexImeChannels  channel,
tVexMotorType  type 
)

Set motor type that this IME is attached to.

Parameters
[in]channelThe encoder channel
[in]typeThe motor type
Note
The IME motor type is different to tVexMotorType for backwards compatibility with the legacy vexPRO code.
void vexImeSetMotor ( tVexImeChannels  channel,
tVexMotor  motor 
)

Set the motor that this IME is attached to.

Parameters
[in]channelThe encoder channel
[in]motorThe motor index
int32_t vexImeMotorGetCount ( tVexMotor  motor)

return encoder count based on motor index

Parameters
[in]motorThe motor index
Returns
The encoder count for the IME attached to the motor
Note
This function was deprecated
uint16_t vexIMEFindEncoders ( void  )

Search bus and add all encoders found (up to 8)

Returns
The number of IMEs found
Note
Internal IME driver use only
void vexIMEDataInit ( imeData ime)

Init data structure for one IME.

param[in] ime A pointer to a imeData structure

Note
Internal IME driver use only
msg_t vexIMEUpdateCounts ( imeData ime)

Read encoder data and then calculate the rpm.

Parameters
[in]imeA pointer to an imeData structure
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
0ime pointer is NULL
Note
Internal IME driver use only
msg_t vexIMEGetVersion ( uint8_t  device,
uint8_t *  buf 
)

Read version from IME.

Parameters
[in]deviceThe IME address
[out]bufPointer to the buffer for reply data
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEGetVendor ( uint8_t  device,
uint8_t *  buf 
)

Read vendor from IME.

Parameters
[in]deviceThe IME address
[out]bufPointer to the buffer for reply data
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEGetDeviceId ( uint8_t  device,
uint8_t *  buf 
)

Read device ID from IME.

Parameters
[in]deviceThe IME address
[out]bufPointer to the buffer for reply data
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEGetStatus ( uint8_t  device,
uint8_t *  buf 
)

Read Status from IME.

Parameters
[in]deviceThe IME address
[out]bufPointer to the buffer for reply data
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEGetData ( uint8_t  device,
uint8_t *  buf 
)

Read encoder data from IME.

Parameters
[in]deviceThe IME address
[out]bufPointer to the buffer for reply data
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEGetScratchpad ( uint8_t  device,
uint8_t *  buf,
uint8_t  offset,
uint8_t  len 
)

Read scratchpad data from IME.

Parameters
[in]deviceThe IME address
[in]bufPointer to the scratchpad data
[in]offsetAn offset into the scratchpad area
[in]lenThe length of the scratchpad data to write
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMESetScratchpad ( uint8_t  device,
uint8_t *  buf,
uint8_t  offset,
uint8_t  len 
)

Write scratchpad data to the IME.

Parameters
[in]deviceThe IME address
[in]bufPointer to the scratchpad data
[in]offsetAn offset into the scratchpad area
[in]lenThe length of the scratchpad data to write
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEClearCounters ( uint8_t  device)

Clear Counters in IME.

Parameters
[in]deviceThe IME address
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEDisableTermination ( uint8_t  device)

Disable termination in IME.

Parameters
[in]deviceThe IME address
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMEEnableTermination ( uint8_t  device)

Enable termination in IME.

Parameters
[in]deviceThe IME address
Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
msg_t vexIMESetAddr ( uint8_t *  device,
uint8_t  newDevice 
)
msg_t vexIMEResetAll ( void  )

Reset an IME.

Returns
The status of the I2C driver
Return values
RDY_OKIf the function succeeded
RDY_RESETif one or more I2C errors occurred.
RDY_TIMEOUTif a timeout occurred before operation end.
Note
Internal IME driver use only
void vexIMEHandleErrors ( msg_t  status,
i2cflags_t  errors 
)

Handle received IME I2C errors.

Parameters
[in]statusThe received message from the I2C low level driver
[in]errorsThe received error status
Note
Internal IME driver use only
void vexIMEPrintBuf ( vexStream chp,
uint8_t *  buf,
uint8_t  len 
)

Print a buffer with IME data.

Parameters
[in]chpA pointer to a vexStream object
[in]bufA pointer to a buffer of uint8_t
[in]lenThe buffer elngth
Note
Used by internal IME debug functions
void vexIMEDebug ( vexStream chp,
int  argc,
char *  argv[] 
)

Debug function to dump IME buffers.

Parameters
[in]chpA pointer to a vexStream object
[in]argcThe number of command line arguments
[in]argvAn array of pointers to the command line args