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

IME driver. More...

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "ch.h"
#include "hal.h"
#include "vex.h"

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...
 
imeDatavexImeGetPtr (tVexImeChannels channel)
 return pointer to IME data structure More...
 
int16_t vexImeGetChannelMax ()
 Get the number of IMEs found. 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...
 
void vexImeInit (I2CDriver *i2cp, vexStream *chp)
 Initialize IMEs on the I2C bus. More...
 
msg_t vexIMEUpdateCounts (imeData *ime)
 Read encoder data and then calculate the rpm. More...
 
void vexIMEDataInit (imeData *ime)
 Init data structure for one IME. More...
 
uint16_t vexIMEFindEncoders ()
 Search bus and add all encoders found (up to 8) 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, unsigned char newDevice)
 Set new Address in IME. More...
 
msg_t vexIMEResetAll ()
 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.

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
imeData* vexImeGetPtr ( tVexImeChannels  channel)

return pointer to IME data structure

Parameters
[in]channelThe encoder channel
Returns
A pointer to an imeData structure
int16_t vexImeGetChannelMax ( void  )

Get the number of IMEs found.

Returns
The number of IMEs that were found during the last init
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
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
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
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
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
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,
unsigned char  newDevice 
)

Set new Address in IME.

Parameters
[in]deviceThe IME address
[in]newDeviceThe new 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 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