Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
CrossWorks Device Library
Version: 3.3
© 2014 Rowley Associates Limited
CrossWorks Device Library
2
CrossWorks Device Library Contents
3
ContentsCrossWorks Device Library .................................................................................................................................................................. 15
Protocol API Reference ........................................................................................................................................................... 17
<ctl_bus.h> .................................................................................................................................................................... 17
CTL_PARALLEL_BUS_t ................................................................................................................................ 18
ctl_bus_lock .................................................................................................................................................... 19
ctl_bus_lock_ex ............................................................................................................................................. 20
ctl_bus_read ................................................................................................................................................... 21
ctl_bus_read_bit ........................................................................................................................................... 22
ctl_bus_set_direction ................................................................................................................................. 23
ctl_bus_set_input_mode ........................................................................................................................... 24
ctl_bus_set_output_mode ....................................................................................................................... 25
ctl_bus_unlock ............................................................................................................................................... 26
ctl_bus_write .................................................................................................................................................. 27
ctl_bus_write_bit .......................................................................................................................................... 28
ctl_bus_write_bits ........................................................................................................................................ 29
ctl_parallel_bus_initialize ......................................................................................................................... 30
<ctl_i2c.h> ...................................................................................................................................................................... 31
CTL_I2C_BUS_t .............................................................................................................................................. 32
CTL_I2C_FAST_MODE_PLUS_SPEED .................................................................................................... 33
CTL_I2C_FAST_MODE_SPEED ................................................................................................................. 34
CTL_I2C_REQUEST_t .................................................................................................................................... 35
CTL_I2C_STANDARD_SPEED .................................................................................................................... 36
ctl_i2c_lock_bus ............................................................................................................................................ 37
CrossWorks Device Library Contents
4
ctl_i2c_lock_bus_ex ..................................................................................................................................... 38
ctl_i2c_read ..................................................................................................................................................... 39
ctl_i2c_set_speed ......................................................................................................................................... 40
ctl_i2c_unlock_bus ...................................................................................................................................... 41
ctl_i2c_write .................................................................................................................................................... 42
ctl_i2c_write_read ........................................................................................................................................ 43
<ctl_spi.h> ..................................................................................................................................................................... 44
CTL_SPI_BUS_t ............................................................................................................................................... 46
CTL_SPI_DEVICE_t ........................................................................................................................................ 47
CTL_SPI_EXCHANGE_FN_t ........................................................................................................................ 48
CTL_SPI_MODE_t .......................................................................................................................................... 49
CTL_SPI_PROTOCOL_t ................................................................................................................................ 50
CTL_SPI_SET_PROTOCOL_FN_t .............................................................................................................. 51
ctl_spi_attach_device ................................................................................................................................. 52
ctl_spi_deselect_device ............................................................................................................................. 53
ctl_spi_detach_device ................................................................................................................................ 54
ctl_spi_exchange .......................................................................................................................................... 55
ctl_spi_get ....................................................................................................................................................... 56
ctl_spi_issue_deselected_clocks ............................................................................................................ 57
ctl_spi_lock_bus ............................................................................................................................................ 58
ctl_spi_lock_bus_ex .................................................................................................................................... 59
ctl_spi_put ....................................................................................................................................................... 60
ctl_spi_put_get .............................................................................................................................................. 61
ctl_spi_read ..................................................................................................................................................... 62
ctl_spi_select_device .................................................................................................................................. 63
ctl_spi_set_idle .............................................................................................................................................. 64
ctl_spi_set_mode .......................................................................................................................................... 65
ctl_spi_set_protocol .................................................................................................................................... 66
ctl_spi_set_speed ......................................................................................................................................... 67
ctl_spi_set_width .......................................................................................................................................... 68
ctl_spi_unlock_bus ...................................................................................................................................... 69
ctl_spi_write .................................................................................................................................................... 70
<ctl_sensors.h> ............................................................................................................................................................ 71
CTL_ACCELEROMETER_t ............................................................................................................................ 73
CTL_AXIS_TRANSFORMATION ................................................................................................................ 75
CTL_GYROSCOPE_t ...................................................................................................................................... 76
CTL_HUMIDITY_SENSOR_t ....................................................................................................................... 78
CTL_IMU_t ....................................................................................................................................................... 79
CTL_LIGHT_SENSOR_t ................................................................................................................................ 80
CTL_MAGNETOMETER_t ............................................................................................................................ 81
CTL_PRESSURE_SENSOR_t ....................................................................................................................... 82
CrossWorks Device Library Contents
5
CTL_TEMPERATURE_SENSOR_t .............................................................................................................. 83
ctl_accelerometer_measure ..................................................................................................................... 84
ctl_accelerometer_set_bandwidth ....................................................................................................... 85
ctl_accelerometer_set_range .................................................................................................................. 86
ctl_forward_transform_axes ................................................................................................................... 87
ctl_generate_axis_transform .................................................................................................................. 88
ctl_gyroscope_measure ............................................................................................................................. 89
ctl_gyroscope_set_bandwidth ............................................................................................................... 90
ctl_gyroscope_set_range .......................................................................................................................... 91
ctl_humidity_sensor_measure ............................................................................................................... 92
ctl_light_sensor_measure ......................................................................................................................... 93
ctl_magnetometer_measure ................................................................................................................... 94
ctl_magnetometer_set_bandwidth ...................................................................................................... 95
ctl_pressure_sensor_measure ................................................................................................................ 96
ctl_temperature_sensor_measure ........................................................................................................ 97
ctl_temperature_sensor_set_resolution ............................................................................................ 98
<ctl_transport.h> ........................................................................................................................................................ 99
CTL_TRANSPORT_BUS_t ......................................................................................................................... 101
CTL_TRANSPORT_t .................................................................................................................................... 102
ctl_transport_initialize_i2c .................................................................................................................... 103
ctl_transport_initialize_spi .................................................................................................................... 104
ctl_transport_lock ...................................................................................................................................... 105
ctl_transport_read_16b_register ........................................................................................................ 106
ctl_transport_read_24b_register ........................................................................................................ 107
ctl_transport_read_32b_register ........................................................................................................ 108
ctl_transport_read_8b_register ........................................................................................................... 109
ctl_transport_read_registers ................................................................................................................ 110
ctl_transport_read_registers_fail ........................................................................................................ 111
ctl_transport_read_registers_i2c ........................................................................................................ 112
ctl_transport_rmw_16b_register ........................................................................................................ 113
ctl_transport_rmw_24b_register ........................................................................................................ 114
ctl_transport_rmw_32b_register ........................................................................................................ 115
ctl_transport_rmw_8b_register ........................................................................................................... 116
ctl_transport_unlock ................................................................................................................................ 117
ctl_transport_write_16b_register ....................................................................................................... 118
ctl_transport_write_24b_register ....................................................................................................... 119
ctl_transport_write_32b_register ....................................................................................................... 120
ctl_transport_write_8b_register ......................................................................................................... 121
ctl_transport_write_registers ............................................................................................................... 122
ctl_transport_write_registers_fail ...................................................................................................... 123
ctl_transport_write_registers_i2c ....................................................................................................... 124
CrossWorks Device Library Contents
6
<ctl_uart.h> ................................................................................................................................................................ 125
ctl_uart_getc ................................................................................................................................................ 126
ctl_uart_getc_nb ........................................................................................................................................ 127
ctl_uart_putc ................................................................................................................................................ 128
ctl_uart_puts ................................................................................................................................................ 129
Device API Reference ............................................................................................................................................................ 130
Analog ........................................................................................................................................................................... 130
<adc101s021.h> ......................................................................................................................................... 130
adc101s021_init ........................................................................................................................... 131
adc101s021_measure_raw ...................................................................................................... 132
<ltc2309.h> ................................................................................................................................................... 133
LTC2309_I2C_ADDR ................................................................................................................... 134
ltc2309_init_i2c ............................................................................................................................ 135
ltc2309_sample_differential_bipolar .................................................................................. 136
ltc2309_sample_differential_unipolar ............................................................................... 137
ltc2309_sample_single_ended_bipolar ............................................................................. 138
ltc2309_sample_single_ended_unipolar .......................................................................... 139
Digital ............................................................................................................................................................................ 140
<mcp23016.h> ............................................................................................................................................ 140
MCP23016_I2C_ADDR ............................................................................................................... 141
mcp23016_initialize_i2c ........................................................................................................... 142
<mcp23x08.h> ............................................................................................................................................ 143
MCP23008_I2C_ADDR ............................................................................................................... 144
mcp23x08_initialize_i2c ........................................................................................................... 145
mcp23x08_initialize_spi ........................................................................................................... 146
<mcp23x17.h> ............................................................................................................................................ 147
MCP23017_I2C_ADDR ............................................................................................................... 148
mcp23x17_initialize_i2c ........................................................................................................... 149
mcp23x17_initialize_spi ........................................................................................................... 150
<pca9532.h> ................................................................................................................................................ 151
PCA9532_I2C_ADDR ................................................................................................................... 152
pca9532_initialize_i2c ............................................................................................................... 153
pca9532_led_mode .................................................................................................................... 154
pca9532_set_duty_cycle .......................................................................................................... 155
pca9532_set_led_mode ............................................................................................................ 156
pca9532_set_pwm_frequency ............................................................................................... 157
<pca9672.h> ................................................................................................................................................ 158
pca9672_initialize_i2c ............................................................................................................... 159
<pcf8575.h> ................................................................................................................................................. 160
PCF8575_I2C_ADDR ................................................................................................................... 161
pcf8575_initialize_i2c ................................................................................................................ 162
CrossWorks Device Library Contents
7
Clock ............................................................................................................................................................................... 163
<ltc6904.h> ................................................................................................................................................... 163
LTC6904_I2C_ADDR_ADR0 ..................................................................................................... 165
LTC6904_I2C_ADDR_ADR1 ..................................................................................................... 166
LTC6904_MODE_CLK_OFF_nCLK_ON ................................................................................. 167
LTC6904_MODE_CLK_ON_nCLK_OFF ................................................................................. 168
LTC6904_MODE_CLK_ON_nCLK_ON .................................................................................. 169
LTC6904_MODE_POWER_DOWN ......................................................................................... 170
LTC6904_OSCILLATOR_t .......................................................................................................... 171
ltc6904_get_selected_frequency ......................................................................................... 172
ltc6904_init_i2c ............................................................................................................................ 173
ltc6904_set_frequency .............................................................................................................. 174
ltc6904_set_mode ....................................................................................................................... 175
Environmental ........................................................................................................................................................... 176
<adt7410.h> ................................................................................................................................................. 176
ADT7410_I2C_ADDR .................................................................................................................. 177
adt7410_initialize_i2c ................................................................................................................ 178
<bmp085.h> ................................................................................................................................................. 179
BMP085_BAROMETER_t ........................................................................................................... 180
BMP085_I2C_ADDR .................................................................................................................... 181
bmp085_initialize_i2c ............................................................................................................... 182
bmp085_set_resolution ............................................................................................................ 183
<dht.h> ........................................................................................................................................................... 184
dht_read_humidity ..................................................................................................................... 185
<hih6130.h> ................................................................................................................................................. 186
HIH6130_I2C_ADDR ................................................................................................................... 187
hih6130_initialize_i2c ................................................................................................................ 188
<isl29023.h> ................................................................................................................................................. 189
ISL29023_DRIVER_t .................................................................................................................... 191
ISL29023_I2C_ADDR .................................................................................................................. 192
isl29023_initialize_i2c ............................................................................................................... 193
isl29023_set_range ..................................................................................................................... 194
isl29023_set_resolution_bits .................................................................................................. 195
<lm75.h> ........................................................................................................................................................ 196
LM75_I2C_ADDR .......................................................................................................................... 197
lm75_initialize_i2c ...................................................................................................................... 198
lm75_initialize_i2c_ex ............................................................................................................... 199
<lps331ap.h> ............................................................................................................................................... 200
LPS331AP_I2C_ADDR ................................................................................................................ 201
lps331ap_initialize_i2c .............................................................................................................. 202
<ltr501als.h> ................................................................................................................................................ 203
CrossWorks Device Library Contents
8
LTR501ALS_I2C_ADDR .............................................................................................................. 204
ltr501als_initialize_i2c ............................................................................................................... 205
<max6675.h> ............................................................................................................................................... 206
max6675_initialize_spi .............................................................................................................. 207
<mpl115a.h> ................................................................................................................................................ 208
MPL115A2_I2C_ADDRESS ........................................................................................................ 210
mpl115a_initialize_i2c ............................................................................................................... 211
mpl115a_initialize_spi .............................................................................................................. 212
<mpl3115a2.h> ........................................................................................................................................... 213
MPL3115A2_I2C_ADDRESS ..................................................................................................... 214
mpl3115a2_initialize_i2c ......................................................................................................... 215
<sht1x.h> ....................................................................................................................................................... 216
SHT1X_HIGH_RESOLUTION ..................................................................................................... 218
SHT1X_LOW_RESOLUTION ...................................................................................................... 219
sht1x_initialize .............................................................................................................................. 220
sht1x_read_linear_humidity ................................................................................................... 221
sht1x_read_raw_humidity ....................................................................................................... 222
sht1x_read_raw_temperature ............................................................................................... 223
sht1x_read_status ....................................................................................................................... 224
sht1x_read_temperature ......................................................................................................... 225
sht1x_read_true_humidity ...................................................................................................... 226
sht1x_set_resolution .................................................................................................................. 227
sht1x_set_supply_voltage ....................................................................................................... 228
sht1x_soft_reset ........................................................................................................................... 229
sht1x_write_status ...................................................................................................................... 230
<sht2x.h> ....................................................................................................................................................... 231
SHT2x_I2C_ADDR ........................................................................................................................ 233
SHT2x_RESOLUTION_t .............................................................................................................. 234
sht2x_get_resolution ................................................................................................................. 235
sht2x_initialize_i2c ..................................................................................................................... 236
sht2x_read_user ........................................................................................................................... 237
sht2x_set_resolution .................................................................................................................. 238
sht2x_write_user ......................................................................................................................... 239
<si7005.h> ..................................................................................................................................................... 240
SI7005_I2C_ADDR ....................................................................................................................... 241
si7005_initialize_i2c ................................................................................................................... 242
<tmp100.h> .................................................................................................................................................. 243
TMP100_I2C_ADDR ..................................................................................................................... 244
tmp100_initialize_i2c ................................................................................................................. 245
<tmp102.h> .................................................................................................................................................. 246
TMP102_I2C_ADDR ..................................................................................................................... 248
CrossWorks Device Library Contents
9
TMP275_I2C_ADDR ..................................................................................................................... 249
tmp102_initialize_i2c ................................................................................................................. 250
tmp102_set_extended_mode ................................................................................................ 251
<tsl2561.h> ................................................................................................................................................... 252
TSL2561_DRIVER_t ...................................................................................................................... 253
TSL2561_I2C_ADDR_FLOAT .................................................................................................... 254
TSL2561_I2C_ADDR_GND ........................................................................................................ 255
TSL2561_I2C_ADDR_VDD ........................................................................................................ 256
tsl2561_initialize_i2c .................................................................................................................. 257
tsl2561_set_integration_time ................................................................................................ 258
HMI .................................................................................................................................................................................. 259
<ads7846.h> ................................................................................................................................................. 259
ads7846_init .................................................................................................................................. 260
<hd44780.h> ................................................................................................................................................ 261
HD44780_4BIT_INTERFACE ..................................................................................................... 263
HD44780_ANSI_DRIVER_t ........................................................................................................ 264
HD44780_BIDIRECTIONAL_DBUS ......................................................................................... 265
HD44780_DRIVER_t .................................................................................................................... 266
hd44780_ansi_init ....................................................................................................................... 268
hd44780_clear .............................................................................................................................. 269
hd44780_cursor_off ................................................................................................................... 270
hd44780_cursor_on .................................................................................................................... 271
hd44780_display_off ................................................................................................................. 272
hd44780_display_on .................................................................................................................. 273
hd44780_putc ............................................................................................................................... 274
hd44780_puts ............................................................................................................................... 275
hd44780_reset .............................................................................................................................. 276
hd44780_send_cmd ................................................................................................................... 277
hd44780_set_backlight ............................................................................................................ 278
hd44780_set_cursor_position ............................................................................................... 279
hd44780_write .............................................................................................................................. 280
<mpr121.h> .................................................................................................................................................. 281
MPR121_ADDRESS_SCL ............................................................................................................ 282
MPR121_ADDRESS_SDA ........................................................................................................... 283
MPR121_ADDRESS_VDD .......................................................................................................... 284
MPR121_ADDRESS_VSS ............................................................................................................ 285
<wii_controller.h> ..................................................................................................................................... 286
WII_CLASSIC_REPORT_t ............................................................................................................ 288
WII_NUNCHUK_REPORT_t ....................................................................................................... 289
wii_classic_sample ...................................................................................................................... 290
wii_extension_controller_initialize ...................................................................................... 291
CrossWorks Device Library Contents
10
wii_extension_controller_read_memory .......................................................................... 292
wii_extension_controller_write_memory_byte ............................................................. 293
wii_nunchuk_accelerometer_interface ............................................................................. 294
wii_nunchuk_sample ................................................................................................................. 295
Magnetics ..................................................................................................................................................................... 296
<ak8975.h> ................................................................................................................................................... 296
AK8975_I2C_ADDR ..................................................................................................................... 298
ak8975_initialize_i2c .................................................................................................................. 299
ak8975_initialize_transport .................................................................................................... 300
<bmm150.h> ............................................................................................................................................... 301
BMM150_I2C_ADDR ................................................................................................................... 302
bmm150_initialize_i2c .............................................................................................................. 303
bmm150_initialize_spi .............................................................................................................. 304
<fxos8700cq.h> .......................................................................................................................................... 305
FXOS8700CQ_I2C_ADDR .......................................................................................................... 306
FXOS8700CQ_t ............................................................................................................................. 307
fxos8700cq_initialize_i2c ......................................................................................................... 308
<hmc5843.h> ............................................................................................................................................... 309
HMC5843_I2C_ADDR ................................................................................................................. 310
hmc5843_initialize_i2c .............................................................................................................. 311
<hmc5883l.h> .............................................................................................................................................. 312
HMC5883L_I2C_ADDR ............................................................................................................... 314
hmc5883l_initialize_i2c ............................................................................................................ 315
hmc5883l_initialize_transport ............................................................................................... 316
<hmc6343.h> ............................................................................................................................................... 317
HMC6343_I2C_ADDR ................................................................................................................. 318
hmc6343_read_heading ........................................................................................................... 319
<hmc6352.h> ............................................................................................................................................... 320
HMC6352_I2C_ADDR ................................................................................................................. 321
hmc6352_read_heading ........................................................................................................... 322
<mag3110.h> ............................................................................................................................................... 323
MAG3110_I2C_ADDR ................................................................................................................. 325
mag3110_initialize_i2c ............................................................................................................. 326
mag3110_read_die_temperature ........................................................................................ 327
mag3110_set_oversampling_ratio ...................................................................................... 328
Motion ........................................................................................................................................................................... 329
<adxl345.h> .................................................................................................................................................. 329
ADXL345_I2C_ADDR_ALTERNATE ....................................................................................... 331
ADXL345_I2C_ADDR_DEFAULT ............................................................................................ 332
adxl345_initialize_i2c ................................................................................................................ 333
adxl345_initialize_spi ................................................................................................................ 334
CrossWorks Device Library Contents
11
<adxl362.h> .................................................................................................................................................. 335
adxl362_initialize_spi ................................................................................................................ 336
<atavrsbin1.h> ............................................................................................................................................ 337
ATAVRSBIN1_t ............................................................................................................................... 338
atavrsbin1_initialize_i2c ........................................................................................................... 339
<atavrsbin2.h> ............................................................................................................................................ 340
ATAVRSBIN2_t ............................................................................................................................... 341
atavrsbin2_initialize_i2c ........................................................................................................... 342
<bma150.h> ................................................................................................................................................. 343
BMA150_I2C_ADDR .................................................................................................................... 345
bma150_initialize_i2c ................................................................................................................ 346
bma150_initialize_spi ................................................................................................................ 347
bma150_read_chip_id ............................................................................................................... 348
bma150_read_die_temperature ........................................................................................... 349
bma150_soft_reset ..................................................................................................................... 350
<bma250.h> ................................................................................................................................................. 351
BMA250_I2C_ADDR .................................................................................................................... 352
bma250_initialize_i2c ................................................................................................................ 353
bma250_initialize_spi ................................................................................................................ 354
bma250_read_chip_id ............................................................................................................... 355
bma250_read_die_temperature ........................................................................................... 356
<imu3000.h> ................................................................................................................................................ 357
IMU3000_I2C_ADDR ................................................................................................................... 358
imu3000_initialize_i2c .............................................................................................................. 359
imu3000_read_die_temperature .......................................................................................... 360
<imu3000_combo.h> ............................................................................................................................... 361
IMU3000_COMBO_t .................................................................................................................... 362
imu3000_combo_initialize_i2c .............................................................................................. 363
<itg3200.h> .................................................................................................................................................. 364
ITG3200_I2C_ADDR .................................................................................................................... 365
itg3200_initialize_i2c ................................................................................................................. 366
itg3200_read_die_temperature ............................................................................................ 367
<kxp84.h> ..................................................................................................................................................... 368
KXP84_I2C_ADDR ........................................................................................................................ 369
kxp84_initialize_i2c .................................................................................................................... 370
kxp84_initialize_spi .................................................................................................................... 371
<kxtf9.h> ....................................................................................................................................................... 372
KXTF9_I2C_ADDR ........................................................................................................................ 373
kxtf9_initialize_i2c ...................................................................................................................... 374
<l3g4200d.h> .............................................................................................................................................. 375
L3G4200D_I2C_ADDR ................................................................................................................ 376
CrossWorks Device Library Contents
12
l3g4200d_initialize_i2c ............................................................................................................. 377
<l3gd20.h> .................................................................................................................................................... 378
L3GD20_I2C_ADDR ..................................................................................................................... 379
l3gd20_initialize_i2c .................................................................................................................. 380
<lis302dl.h> .................................................................................................................................................. 381
LIS302DL_I2C_ADDR .................................................................................................................. 383
lis302dl_initialize_i2c ................................................................................................................. 384
lis302dl_initialize_spi ................................................................................................................. 385
<lis331dlh.h> ............................................................................................................................................... 386
LIS331DLH_I2C_ADDR ............................................................................................................... 388
lis331dlh_initialize_i2c .............................................................................................................. 389
lis331dlh_initialize_spi .............................................................................................................. 390
<lis331hh.h> ................................................................................................................................................ 391
LIS331HH_I2C_ADDR ................................................................................................................. 393
lis331hh_initialize_i2c ............................................................................................................... 394
lis331hh_initialize_spi ............................................................................................................... 395
<lis3dsh.h> ................................................................................................................................................... 396
LIS3DSH_I2C_ADDR .................................................................................................................... 397
lis3dsh_initialize_i2c .................................................................................................................. 398
lis3dsh_initialize_spi .................................................................................................................. 399
<lis3lv02dl.h> .............................................................................................................................................. 400
LIS3LV02DL_I2C_ADDR ............................................................................................................. 401
lis3lv02dl_initialize_i2c ............................................................................................................. 402
lis3lv02dl_initialize_spi ............................................................................................................. 403
<mma7455l.h> ............................................................................................................................................ 404
MMA7455_I2C_ADDR ................................................................................................................ 405
mma7455l_initialize_i2c ........................................................................................................... 406
mma7455l_initialize_spi ........................................................................................................... 407
<mma7660fc.h> .......................................................................................................................................... 408
MMA7660FC_I2C_ADDR ........................................................................................................... 409
mma7660fc_initialize_i2c ........................................................................................................ 410
<mma845xq.h> ........................................................................................................................................... 411
MMA8451Q_I2C_ADDR ............................................................................................................. 413
mma8451q_initialize_i2c ......................................................................................................... 414
<mma8491q.h> .......................................................................................................................................... 415
MMA8491Q_I2C_ADDR ............................................................................................................. 416
mma8491q_initialize_i2c ......................................................................................................... 417
<mpu6000.h> .............................................................................................................................................. 418
MPU6000_I2C_ADDR ................................................................................................................. 419
MPU6000_t ..................................................................................................................................... 420
mpu6000_aux_transport_setup ........................................................................................... 421
CrossWorks Device Library Contents
13
mpu6000_initialize_i2c ............................................................................................................. 422
mpu6000_initialize_spi ............................................................................................................. 423
mpu6000_read_die_temperature ........................................................................................ 424
mpu6000_revision ...................................................................................................................... 425
<sca3000.h> ................................................................................................................................................. 426
sca3000_initialize_i2c ................................................................................................................ 428
sca3000_initialize_spi ................................................................................................................ 429
CrossWorks Device Library Contents
14
CrossWorks Device Library CrossWorks Device Library
15
CrossWorks Device LibraryThe CrossWorks Device Library contains pre-written, tested device driver software to interact with a range of
common sensors and devices. This library will be extended over time, as more devices become available and are
considered for inclusion in the library.
The device library is split into two parts:
• Protocol API: provides an abstract interface to common industry protocols, such as I2C and SPI, along with
an API for generic sensor functions.
• Device API: provides specific device implementations for the generic sensor functions and drivers for
unique or special devices.
Architecture
The CrossWorks Device Library is one part of the CrossWorks Target Library. Many of the low-level functions
provided by the target library are built using features of the CrossWorks Tasking Library for multi-threaded
operation.
Delivery format
The CrossWorks Device Library is delivered in source form.
License
The source files in this package are not public domain and are not open source. They represent a substantial
investment undertaken by Rowley Associates to assist CrossWorks customers in prototyping solutions using
well-written, tested drivers.
CrossWorks Device Library CrossWorks Device Library
16
If you hold a paid-for CrossWorks Version 3 or later commercial license, you are free to compile this package and
incorporate the resulting object code in your own products without royalties and without additional license
fees. Customers holding a CrossWorks Version 1 or 2 commercial license are required to upgrade to CrossWorks
Version 3 to use this software.
If you hold a paid-for CrossWorks Version 3 or later non-commercial license, you are free to compile this package
and incorporate the resulting object code in your own projects, for your own use, without royalties and without
additional license fees. You are, however, prohibited from distributing the linked code, incorporating the object
code from this library, in binary form. Customers holding a CrossWorks Version 1 or 2 non-commercial license are
required to purchase CrossWorks Version 3 to use this software.
Feedback
This facility is a work in progress and may undergo rapid change. If you have comments, observations,
suggestions, or problems, please feel free to air them on the CrossWorks Target and Platform API discussion
forum.
CrossWorks Device Library CrossWorks Device Library
17
<ctl_bus.h>
Overview
Abstract parallel digital bus.
The types and functions in <ctl_i2c.h> provide a high-level set of services that implement a parallel bus.
The CrossWorks Device Library provides drivers for the following devices that implement a parallel bus but are
connected using I2C or SPI:
• MCP23x08
• MCP23016
• MCP23x17
• PCF8575
• PCA9672
API Summary
Bus
CTL_PARALLEL_BUS_t Abstract parallel bus interface
ctl_bus_lock Acquire exclusive bus lock
ctl_bus_lock_ex Acquire exclusive bus lock (extended)
ctl_bus_unlock Release exclusive bus lock
ctl_parallel_bus_initialize Initialize structure
Configuration
ctl_bus_set_direction Set bus input-output direction
ctl_bus_set_input_mode Set selected bus bits to input direction
ctl_bus_set_output_mode Set selected bus bits to output direction
I/O
ctl_bus_read Read entire bus
ctl_bus_read_bit Read a single bit from bus
ctl_bus_write Write entire bus output
ctl_bus_write_bit Write a single bit to bus
ctl_bus_write_bits Write bits to bus through a mask
CrossWorks Device Library CrossWorks Device Library
18
CTL_PARALLEL_BUS_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*set_direction)(CTL_PARALLEL_BUS_s *, unsigned); CTL_STATUS_t (*write)(CTL_PARALLEL_BUS_s *, unsigned); CTL_STATUS_t (*read)(CTL_PARALLEL_BUS_s *); CTL_MUTEX_t *mutex; unsigned __width; unsigned __output; unsigned __direction; unsigned __mask;} CTL_PARALLEL_BUS_t;
Description
CTL_PARALLEL_BUS_t contains the bus state and methods that implement a parallel bus. Clients that use the
parallel bus should consider all data in this structure private.
Structure
transport
Underlying transport for parallel buses realized by I2C or SPI devices.
set_direction
Method to set the bus direction.
write
Method to set the bus pins.
read
Method to read the bus pins.
__width
The bus width, in bits.
__output
The bus output state.
__direction
The bus direction.
__mask
The bus mask corresponding to __width.
CrossWorks Device Library CrossWorks Device Library
19
ctl_bus_lock
Synopsis
void ctl_bus_lock(CTL_PARALLEL_BUS_t *self);
Description
ctl_bus_lock acquires the bus lock mutex of the bus self. If there is no mutex associated with the bus self,
ctl_bus_lock returns immediately indicating success.
All locks of the bus by ctl_bus_lock must be paired with a call to ctl_bus_unlock to release the lock.
Note
Because mutexes can be locked multiple times, you can use ctl_bus_lock to acquire the bus to issue a sequence
of transactions to the bus that cannot be interrupted by another task.
See Also
ctl_bus_unlock, ctl_bus_lock_ex
CrossWorks Device Library CrossWorks Device Library
20
ctl_bus_lock_ex
Synopsis
unsigned ctl_bus_lock_ex(CTL_PARALLEL_BUS_t *self, CTL_TIMEOUT_t type, CTL_TIME_t time);
Description
ctl_bus_lock_ex acquires the bus lock mutex of the bus self using the timeout specified with type and time. If
there is no mutex associated with the bus self, ctl_bus_lock_ex returns immediately indicating success.
ctl_bus_lock_ex returns a non-zero value if the mutex is acquired within the timeout specification and zero if it
is not.
All successful locks of the bus by ctl_bus_lock_ex must be paired with a call to ctl_bus_unlock to release the
lock.
See Also
ctl_bus_unlock_bus, ctl_bus_lock
CrossWorks Device Library CrossWorks Device Library
21
ctl_bus_read
Synopsis
CTL_STATUS_t ctl_bus_read(CTL_PARALLEL_BUS_t *self);
Description
ctl_bus_read reads the state of the bus self.
Note that reading bits configured as output is highly device dependent and the effect of doing so is not
specified by this interface.
Thread Safety
ctl_bus_read is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
22
ctl_bus_read_bit
Synopsis
CTL_STATUS_t ctl_bus_read_bit(CTL_PARALLEL_BUS_t *self, unsigned bit);
Description
ctl_bus_read_bit reads bit number bit from the bus self.
Return Value
ctl_bus_read_bit returns an extended status code: 0 if the port bit is low, 1 if the port bit is high, and a negative
value indicating an error.
Thread Safety
ctl_bus_read_bit is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
23
ctl_bus_set_direction
Synopsis
CTL_STATUS_t ctl_bus_set_direction(CTL_PARALLEL_BUS_t *self, unsigned direction);
Description
ctl_bus_set_direction configures the entire bus for input mode or output mode. A bit set to one in direction
sets the corresponding bus bit to input mode, and a bit set to zero in direction sets the corresponding bus bit to
output mode.
The state of the bus outputs corresponding to direction is indeterminate after setting the bus direction.
Return Value
ctl_bus_set_direction returns a standard status code.
Thread Safety
ctl_bus_set_direction is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
24
ctl_bus_set_input_mode
Synopsis
CTL_STATUS_t ctl_bus_set_input_mode(CTL_PARALLEL_BUS_t *self, unsigned mask);
Description
ctl_bus_set_input_mode sets all corresponding one-bits in mask to input mode for the bus self. If a bit is zero in
mask, the input-output direction of that bit is unchanged.
Return Value
ctl_bus_set_input_mode returns a standard status code.
Thread Safety
ctl_bus_set_input_mode is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
25
ctl_bus_set_output_mode
Synopsis
CTL_STATUS_t ctl_bus_set_output_mode(CTL_PARALLEL_BUS_t *self, unsigned mask);
Description
ctl_bus_set_output_mode sets all corresponding one-bits in mask to output mode for the bus self. If a bit is
zero in mask, the input-output direction of that bit is unchanged.
The state of bus outputs for bits that are changed from input mode to output mode is undefined after setting
the bus direction.
Return Value
ctl_bus_set_output_mode returns a standard status code.
Thread Safety
ctl_bus_set_output_mode is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
26
ctl_bus_unlock
Synopsis
void ctl_bus_unlock(CTL_PARALLEL_BUS_t *self);
Description
ctl_bus_unlock releases a mutex that was successfully locked using ctl_bus_lock. If there is no mutex associated
with the bus self, ctl_bus_unlock returns immediately. It is an error to release a lock that was not acquired
successfully.
See Also
ctl_bus_lock, ctl_bus_lock_ex
CrossWorks Device Library CrossWorks Device Library
27
ctl_bus_write
Synopsis
CTL_STATUS_t ctl_bus_write(CTL_PARALLEL_BUS_t *self, unsigned output);
Description
ctl_bus_write writes output to the bus self. Note that writing to output bits configured as inputs is highly device
dependent and the effect of doing so is not specified by this interface.
Return Value
ctl_bus_write returns a standard status code.
Thread Safety
ctl_bus_write is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
28
ctl_bus_write_bit
Synopsis
CTL_STATUS_t ctl_bus_write_bit(CTL_PARALLEL_BUS_t *self, unsigned bit, unsigned value);
Description
ctl_bus_write_bit sets bit bit on the bus self to value.
If value is zero, the corresponding bit is cleared to zero and if value is non-zero, the corresponding bit is set to
one.
Note that writing to output bits configured as inputs is highly device dependent and the effect of doing so is not
specified by this interface.
Return Value
ctl_bus_write_bit returns a standard status code.
Thread Safety
ctl_bus_write_bit is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
29
ctl_bus_write_bits
Synopsis
CTL_STATUS_t ctl_bus_write_bits(CTL_PARALLEL_BUS_t *self, unsigned mask, unsigned value);
Description
ctl_bus_write_bits writes the bits in value to the bus self. Only the bits that are set to one in mask are written to
the bus which allows the client to both set and clear bits in a single operation.
Return Value
ctl_bus_write_bits returns a standard status code.
Thread Safety
ctl_bus_write_bits is thread-safe if a mutex is associated with the bus self.
CrossWorks Device Library CrossWorks Device Library
30
ctl_parallel_bus_initialize
Synopsis
void ctl_parallel_bus_initialize(CTL_PARALLEL_BUS_t *self);
Description
ctl_parallel_bus_initialize initializes the parallel bus self by setting all members to zero.
CrossWorks Device Library CrossWorks Device Library
31
<ctl_i2c.h>
Overview
Abstract I2C bus interface.
The types and functions in <ctl_i2c.h> provide a high-level set of services for a bus master to read and write
data over one or more I2C buses. Additional features, such as sensor drivers and so on, build upon the services
that the I2C interface offers. In addition, all I2C-interfaced devices in the CrossWorks Micro-Graphics Library use
the I2C functions here for I/O to LCD and OLED displays.
The I2C interface in this library is abstract in the sense that there is no concrete implementation within the
library. Rather, implementations of the I2C interface are offered by the many driver packages that you can install
as a CrossWorks package.
To see examples of this API in use, please install the CrossWorks demonstration package for your particular
board and open up its contents in the Project Explorer and take a look around.
API Summary
Bus
CTL_I2C_BUS_t Abstract I2C bus interface
ctl_i2c_lock_bus Acquire exclusive bus lock
ctl_i2c_lock_bus_ex Acquire exclusive bus lock (extended)
ctl_i2c_set_speed Set I2C bus speed
ctl_i2c_unlock_bus Release exclusive bus lock
I/O
ctl_i2c_read Read data from I2C bus
ctl_i2c_write Write data to I2C bus
ctl_i2c_write_read Write to then read from I2C bus
Implementation
CTL_I2C_REQUEST_t I/O request block
Constants
CTL_I2C_FAST_MODE_PLUS_SPEED I2C fast-mode+ bus speed
CTL_I2C_FAST_MODE_SPEED I2C fast-mode bus speed
CTL_I2C_STANDARD_SPEED I2C standard bus speed
CrossWorks Device Library CrossWorks Device Library
32
CTL_I2C_BUS_t
Synopsis
typedef struct { CTL_STATUS_t (*transaction)(CTL_I2C_BUS_t *, CTL_I2C_REQUEST_t *); CTL_STATUS_t (*set_speed)(CTL_I2C_BUS_t *, unsigned); unsigned long __speed; CTL_MUTEX_t *mutex;} CTL_I2C_BUS_t;
Description
CTL_I2C_BUS_t defines the interface to the device-independent I2C bus driver.
Structure
transaction
Private method to execute an I/O transaction on the I2C bus.
set_speed
Private method to set the operating speed of the I2C bus.
__speed
Consider this a read-only variable that indicates the selected speed of the I2C bus.
mutex
If this mutex is non-zero, the I2C functions will acquire the mutex before proceeding to use the I2C bus. For
systems that do not share the I2C bus between tasks, the mutex can be zero and it's the user's responsibility
to ensure mutual exclusion on the I2C bus.
CrossWorks Device Library CrossWorks Device Library
33
CTL_I2C_FAST_MODE_PLUS_SPEED
Synopsis
#define CTL_I2C_FAST_MODE_PLUS_SPEED 1000000UL // 1 MHz
Description
CTL_I2C_FAST_MODE_PLUS_SPEED defines the standard I2C fast-mode+ bus speed of 1 MHz.
CrossWorks Device Library CrossWorks Device Library
34
CTL_I2C_FAST_MODE_SPEED
Synopsis
#define CTL_I2C_FAST_MODE_SPEED 400000UL // 400 kHz
Description
CTL_I2C_FAST_MODE_SPEED defines the standard I2C fast-mode bus speed of 400 kHz.
CrossWorks Device Library CrossWorks Device Library
35
CTL_I2C_REQUEST_t
Synopsis
typedef struct { unsigned address; const unsigned char *tx; size_t txlen; unsigned char *rx; size_t rxlen;} CTL_I2C_REQUEST_t;
Description
CTL_I2C_REQUEST_t is an I/O request block for an I2C transaction. Clients are not required to use this request
block directly from the I2C API, but I2C drivers are required to implement I/O requests according to the block's
members:
• Write-Read request: If both tx and rx are non-null, the I/O request first writes the slave address and data
specified by tx and txlen to the bus, issues a repeated start, and reads rxlen bytes from the bus into rx,
and finally issues a stop.
• Write request: If tx is non-null and rx is null, the I/O request writes the slave address and data specified by
tx and txlen to the bus, and then issues a stop.
• Read request: If tx is null and rx is non-null, the I/O request writes the slave address to the bus, reads rxlen
bytes from the bus to rx, and issues a stop.
Structure
address
8-bit address for the I/O request. The low order bit is undefined when passed to the low-level I2C driver, and
the I2C driver must correctly set or reset the R/W bit according to the request phase.
tx
A pointer to the data to write to the bus after the slave address is transmitted. If tx is zero, the driver must
skip the write part of the I/O request.
txlen
The number of bytes to transfer as payload in the write part of the I/O request.
rx
A pointer to the data to read from the bus after the slave address is transmitted. If rx is zero, the driver must
skip the read part of the I/O request.
rxlen
The number of bytes to transfer as payload in the read part of the I/O request.
CrossWorks Device Library CrossWorks Device Library
36
CTL_I2C_STANDARD_SPEED
Synopsis
#define CTL_I2C_STANDARD_SPEED 100000UL // 100 kHz
Description
CTL_I2C_STANDARD_SPEED defines the standard I2C bus speed of 100 kHz.
CrossWorks Device Library CrossWorks Device Library
37
ctl_i2c_lock_bus
Synopsis
void ctl_i2c_lock_bus(CTL_I2C_BUS_t *self);
Description
ctl_i2c_lock_bus acquires the bus lock mutex of the I2C bus self. If there is no mutex associated with the bus
self, ctl_i2c_lock_bus returns immediately indicating success.
All locks of the I2C bus by ctl_i2c_lock_bus must be paired with a call to ctl_i2c_unlock_bus to release the lock.
Note
Because mutexes can be locked multiple times, you can use ctl_i2c_lock_bus to acquire the bus to issue a
sequence of I2C transactions to the bus that cannot be interrupted by another task. However, locking the bus
this way does not guarantee that other masters, in a multi-master system, are excluded from issuing transactions
on the bus.
See Also
ctl_i2c_unlock_bus, ctl_i2c_lock_bus_ex
CrossWorks Device Library CrossWorks Device Library
38
ctl_i2c_lock_bus_ex
Synopsis
unsigned ctl_i2c_lock_bus_ex(CTL_I2C_BUS_t *self, CTL_TIMEOUT_t type, CTL_TIME_t time);
Description
ctl_i2c_lock_bus_ex acquires the bus lock mutex of the I2C bus self using the timeout specified with type and
time. If there is no mutex associated with the bus self, ctl_i2c_lock_bus_ex returns immediately indicating
success.
ctl_i2c_lock_bus_ex returns a non-zero value if the mutex is acquired within the timeout specification and zero
if it is not.
All successful locks of the I2C bus by ctl_i2c_lock_bus_ex must be paired with a call to ctl_i2c_unlock_bus to
release the lock.
Note
Because mutexes can be locked multiple times, you can use ctl_i2c_lock_bus_ex to acquire the bus to issue a
sequence of I2C transactions to the bus that cannot be interrupted by another task. However, locking the bus
this way does not guarantee that other masters, in a multi-master system, are excluded from issuing transactions
on the bus.
See Also
ctl_i2c_unlock_bus, ctl_i2c_lock_bus
CrossWorks Device Library CrossWorks Device Library
39
ctl_i2c_read
Synopsis
CTL_STATUS_t ctl_i2c_read(CTL_I2C_BUS_t *self, unsigned address, void *rx, size_t len);
Description
ctl_i2c_read locks the I2C bus self using ctl_i2c_lock_bus and proceeds to read len bytes from the device with
8-bit slave address address and writes them to the object pointed to by rx which must be at least len bytes in
size.
ctl_i2c_read waits unconditionally for the write and read to complete, unlocks the bus using
ctl_i2c_unlock_bus, and returns a standard status code.
For exact I2C transaction details, see CTL_I2C_REQUEST_t.
Thread Safety
This function is thread-safe if a mutex is associated with the I2C bus self.
See Also
CTL_I2C_REQUEST_t.
CrossWorks Device Library CrossWorks Device Library
40
ctl_i2c_set_speed
Synopsis
CTL_STATUS_t ctl_i2c_set_speed(CTL_I2C_BUS_t *self, unsigned long speed);
Description
ctl_i2c_set_speed sets the operating speed of the I2C bus self to speed hertz. If the bus does not support the
requested speed, the speed closest to, but not exceeding, speed is selected.
Return Value
ctl_i2c_set_speed returns a standard status code.
Thread Safety
ctl_i2c_set_speed is thread-safe if a mutex is associated with the I2C bus self.
CrossWorks Device Library CrossWorks Device Library
41
ctl_i2c_unlock_bus
Synopsis
void ctl_i2c_unlock_bus(CTL_I2C_BUS_t *self);
Description
ctl_i2c_unlock_bus releases a mutex that was successfully locked using ctl_i2c_lock_bus. If there is no mutex
associated with the bus self, ctl_i2c_unlock_bus returns immediately. It is an error to release a lock that was not
acquired successfully.
See Also
ctl_i2c_lock_bus, ctl_i2c_lock_bus_ex
CrossWorks Device Library CrossWorks Device Library
42
ctl_i2c_write
Synopsis
CTL_STATUS_t ctl_i2c_write(CTL_I2C_BUS_t *self, unsigned address, const void *tx, size_t len);
Description
ctl_i2c_write locks the I2C bus self using ctl_i2c_lock_bus and proceeds to write the object pointed to by tx
with size len bytes to the device with 8-bit slave address address.
ctl_i2c_write waits unconditionally for the write and read to complete, unlocks the bus using
ctl_i2c_unlock_bus, and returns a standard status code.
For exact I2C transaction details, see CTL_I2C_REQUEST_t.
See Also
CTL_I2C_REQUEST_t.
CrossWorks Device Library CrossWorks Device Library
43
ctl_i2c_write_read
Synopsis
CTL_STATUS_t ctl_i2c_write_read(CTL_I2C_BUS_t *self, unsigned address, const void *tx, size_t txlen, void *rx, size_t rxlen);
Description
ctl_i2c_write_read locks the I2C bus self using ctl_i2c_lock_bus and proceeds to write the object pointed to by
tx with size txlen bytes to device with 8-bit slave address address.
ctl_i2c_write_read then issues a repeated start to the same slave address and reads len bytes from the slave and
writes them to the object pointed to by rx which must be at least rxlen bytes in size.
ctl_i2c_write_read waits unconditionally for the write and read to complete, unlocks the bus using
ctl_i2c_unlock_bus, and returns a standard status code.
For exact I2C transaction details, see CTL_I2C_REQUEST_t.
Thread Safety
This function is thread-safe if a mutex is associated with the I2C bus self.
See Also
CTL_I2C_REQUEST_t.
CrossWorks Device Library CrossWorks Device Library
44
<ctl_spi.h>
Overview
Abstract SPI bus interface.
The types and functions in <ctl_spi.h> provide a high-level set of services for a bus master to read and write
data over one or more SPI buses. Additional features, such as sensor drivers and so on, build upon the services
that the SPI interface offers. In addition, all SPI-interfaced devices in the CrossWorks Micro-Graphics Library use
the SPI functions here for I/O to LCD and OLED display.
The SPI interface in this library is abstract in the sense that there is no concrete implementation within the
library. Rather, implementations of the SPI interface are offered by the many driver packages that you can install
as a CrossWorks package.
To see examples of this API in use, please install the CrossWorks demonstration package for your particular
board and open up its contents in the Project Explorer and take a look around.
API Summary
Bus
CTL_SPI_BUS_t Abstract SPI bus interface
ctl_spi_attach_device Attach device to SPI bus
ctl_spi_deselect_device Deselect a device from SPI bus
ctl_spi_detach_device Detach device from SPI bus
ctl_spi_lock_bus Lock SPI bus
ctl_spi_lock_bus_ex Lock SPI bus (extended)
ctl_spi_select_device Select a device onto SPI bus
ctl_spi_unlock_bus Unlock SPI bus
Device
CTL_SPI_DEVICE_t SPI device instance
CTL_SPI_MODE_t SPI device mode
CTL_SPI_PROTOCOL_t SPI device configuration
ctl_spi_exchange Exchange data with SPI device
ctl_spi_get Read one frame from SPI device
ctl_spi_issue_deselected_clocks Issue clocks to SPI bus with device deselected
ctl_spi_put Write one frame to SPI device
ctl_spi_put_get Exchange one frame with SPI device
ctl_spi_read Read from SPI device
CrossWorks Device Library CrossWorks Device Library
45
ctl_spi_set_idle Set SPI device idle state
ctl_spi_set_mode Set SPI device mode
ctl_spi_set_protocol Set SPI device operating parameters
ctl_spi_set_speed Set SPI device clock speed
ctl_spi_set_width Set SPI device frame width
ctl_spi_write Write to SPI device
Implementation
CTL_SPI_EXCHANGE_FN_t Exchange method prototype
CTL_SPI_SET_PROTOCOL_FN_t Set bus protocol prototype
CrossWorks Device Library CrossWorks Device Library
46
CTL_SPI_BUS_t
Synopsis
typedef struct { CTL_MUTEX_t *mutex; CTL_SPI_SET_PROTOCOL_FN_t __set_protocol; CTL_SPI_EXCHANGE_FN_t __exchange; CTL_SPI_DEVICE_t *__head; CTL_SPI_DEVICE_t *__dev; CTL_SPI_PROTOCOL_t __protocol;} CTL_SPI_BUS_t;
Description
CTL_SPI_BUS_t contains the bus state and methods that implement an SPI bus. Clients that use the SPI bus
should consider all data in this structure private.
Structure
mutex
If this mutex is non-zero, the SPI functions will acquire the mutex proceeding to use the SPI bus. For systems
that do not share the SPI bus between tasks, the mutex can be zero and it's the user's responsibility to
ensure mutual exclusion on the SPI bus.
__set_protocol
Private method to set the SPI bus protocol for a selected device. Client code must not call this method
directly. See CTL_SPI_SET_PROTOCOL_FN_t.
__exchange
Private method to exchange data over the SPI bus. Client code must not call this method directly. See
CTL_SPI_EXCHANGE_FN_t.
__head
Private member which is the head of the chain of devices attached to this SPI bus.
__dev
Private member that stores the currently-selected device on the SPI bus; if null, no device is selected.
__protocol
Private member that stores the protocol that the SPI bus is currently configured for.
CrossWorks Device Library CrossWorks Device Library
47
CTL_SPI_DEVICE_t
Synopsis
typedef struct { int addr; void *extra; void (*select)(CTL_SPI_DEVICE_s *, int); CTL_SPI_DEVICE_s *__next; CTL_SPI_PROTOCOL_t __protocol; CTL_SPI_BUS_t *__bus;} CTL_SPI_DEVICE_t;
Description
CTL_SPI_DEVICE_t defines the device selection method and protocol to use when communicating with a device
on an SPI bus.
Structure
addr
Client-side data. If you are using a single method to select multiple devices, you can use the addr member
of each SPI device structure to distinguish the device.
extra
Client-side data. You can use this member to point to additional data associated with the SPI device.
select
Method to select the device. When the API requires a device to become selected, it calls select with the
appropriate SPI device instance and state as 0. When a device needs to be deselected, it calls select with
the device instance and state non-zero.
__next
Private member that links SPI device instances attached to the same SPI bus.
__protocol
Private member that contains the SPI protocol associated with the device instance.
__bus
Private member that points to the bus the SPI device is attached to. If the device is not attached to a bus,
this member is null.
CrossWorks Device Library CrossWorks Device Library
48
CTL_SPI_EXCHANGE_FN_t
Synopsis
typedef void (*CTL_SPI_EXCHANGE_FN_t)(CTL_SPI_BUS_t *, const void *, void *, size_t);
Description
CTL_SPI_EXCHANGE_FN_t is the prototype for the implementation of data exchange on an SPI bus.
CrossWorks Device Library CrossWorks Device Library
49
CTL_SPI_MODE_t
Synopsis
typedef enum { CTL_SPI_CPOL_0, CTL_SPI_CPOL_1, CTL_SPI_CPHA_0, CTL_SPI_CPHA_1, CTL_SPI_MODE0, CTL_SPI_MODE1, CTL_SPI_MODE2, CTL_SPI_MODE3} CTL_SPI_MODE_t;
Description
CTL_SPI_MODE_t defines the four operating modes of the SPI bus, 0 through 3.
CrossWorks Device Library CrossWorks Device Library
50
CTL_SPI_PROTOCOL_t
Synopsis
typedef struct { unsigned char mode; unsigned char width; unsigned short idle; unsigned short options; unsigned long speed;} CTL_SPI_PROTOCOL_t;
Description
CTL_SPI_PROTOCOL_t defines the protocol that an SPI device is configured for, or the current configuration of
the SPI bus.
Structure
mode
Operating mode of the SPI bus, 0 through 3.
width
Width of one frame over the SPI bus. Some SPI drivers support only fixed frame widths, or a subset of frame
widths, so refer to the documentation of your device to determine the supported frame widths.
idle
Either 0 or 0xffff which indicates the state MOSI is driven to when reading from the SPI bus. Some SPI
devices require that MOSI is driven either high or low when reading from the bus.
options
Additional options private to the SPI driver. Typically this is used for storing DMA configuration.
speed
The operating speed of the SPI bus or SPI device, in hertz.
CrossWorks Device Library CrossWorks Device Library
51
CTL_SPI_SET_PROTOCOL_FN_t
Synopsis
typedef CTL_STATUS_t (*CTL_SPI_SET_PROTOCOL_FN_t)(CTL_SPI_BUS_t *);
Description
CTL_SPI_SET_PROTOCOL_FN_t is the prototype for setting the SPI bus protocol (phase, polarity, bus speed, idle
state) prior to selecting the device.
CrossWorks Device Library CrossWorks Device Library
52
ctl_spi_attach_device
Synopsis
CTL_STATUS_t ctl_spi_attach_device(CTL_SPI_BUS_t *self, CTL_SPI_DEVICE_t *dev);
Description
ctl_spi_attach_device attaches the device dev to the SPI bus self. It is an error to operate an SPI device using SPI
functions without first attaching it to a bus.
Thread Safety
ctl_spi_attach_device is thread-safe.
See Also
ctl_spi_detach_device.
CrossWorks Device Library CrossWorks Device Library
53
ctl_spi_deselect_device
Synopsis
void ctl_spi_deselect_device(CTL_SPI_DEVICE_t *self);
Description
ctl_spi_deselect_device deselects the device self on the bus that it is attached to. To do this, the device's select
method is invoked with a non-zero state, and releases the lock on the SPI bus.
Deselecting a deselected device acts as a no-operation.
CrossWorks Device Library CrossWorks Device Library
54
ctl_spi_detach_device
Synopsis
CTL_STATUS_t ctl_spi_detach_device(CTL_SPI_DEVICE_t *self);
Description
ctl_spi_detach_device removes the device self from the bus it's attached to. If the device is already detached
this is a no-operation.
Thread Safety
ctl_spi_detach_device is thread-safe.
See Also
ctl_spi_attach_device.
CrossWorks Device Library CrossWorks Device Library
55
ctl_spi_exchange
Synopsis
CTL_STATUS_t ctl_spi_exchange(CTL_SPI_DEVICE_t *self, const void *tx, void *rx, size_t items);
Description
ctl_spi_exchange simultaneously writes to and reads from the SPI device self which must have been selected
onto the bus by ctl_spi_select_device.
If the selected frame width for the device self is eight bits or narrower, items bytes are written from tx and items
bytes are read from the SPI bus to rx. If the transfer width is nine bits or wider then shorts are used rather than
bytes.
If tx is zero, the set idle-pattern is written to the SPI device (if the the underlying driver supports such a null
transfer). Note that some SPI drivers which use DMA may not support null transfers.
If rx is zero, data are read from the SPI bus and discarded if the underlying driver supports such a null transfer.
Note that some SPI drivers which use DMA may not support null transfers.
CrossWorks Device Library CrossWorks Device Library
56
ctl_spi_get
Synopsis
CTL_STATUS_t ctl_spi_get(CTL_SPI_DEVICE_t *self);
Description
ctl_spi_get reads a single frame from the SPI device self which must have been previously selected onto the bus
by ctl_spi_select_device. The idle value set in the device's protocol is written to the SPI bus when exchanging
data with the device.
Return Value
The value returned is the frame read from the SPI bus; negative values are standard status codes.
CrossWorks Device Library CrossWorks Device Library
57
ctl_spi_issue_deselected_clocks
Synopsis
CTL_STATUS_t ctl_spi_issue_deselected_clocks(CTL_SPI_DEVICE_t *self, size_t items);
Description
ctl_spi_issue_deselected_clocks locks the SPI bus associated with the device self and sets the bus protocol to
communicate with the device. However, the device is not selected onto the bus and remains deselected.
Description
ctl_spi_issue_deselected_clocks then issues items frames of clock pulses to the SPI bus, unlocks the SPI bus,
and returns.
This function is provided primarily for initializing SD and MMC cards into SPI mode.
Description
ctl_spi_issue_deselected_clocks returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
58
ctl_spi_lock_bus
Synopsis
void ctl_spi_lock_bus(CTL_SPI_BUS_t *self);
Description
ctl_spi_lock_bus acquires the bus lock mutex of the SPI bus self. If there is no mutex associated with the bus
self, ctl_spi_lock_bus returns immediately.
All locks of the SPI bus by ctl_spi_lock_bus must be paired with a call to ctl_spi_unlock_bus to release the lock.
Note
Because mutexes can be locked multiple times, you can use ctl_spi_lock_bus to ensure exclusive use of the bus
in order to issue a sequence sequence of SPI transactions without interruption.
See Also
ctl_spi_unlock_bus, ctl_spi_lock_bus_ex
CrossWorks Device Library CrossWorks Device Library
59
ctl_spi_lock_bus_ex
Synopsis
unsigned ctl_spi_lock_bus_ex(CTL_SPI_BUS_t *self, CTL_TIMEOUT_t type, CTL_TIME_t time);
Description
ctl_spi_lock_bus_ex acquires the bus lock mutex of the SPI bus self using the timeout specified with type and
time. If there is no mutex associated with the bus self, ctl_spi_lock_bus_ex returns immediately indicating
success.
ctl_spi_lock_bus_ex returns a non-zero value if the mutex is acquired within the timeout specification and zero
if it is not.
All successful locks of the SPI bus by ctl_spi_lock_bus_ex must be paired with a call to ctl_spi_unlock_bus to
release the lock.
Note
Because mutexes can be locked multiple times, you can use ctl_spi_lock_bus_ex to ensure exclusive use of the
bus in order to issue a sequence sequence of SPI transactions without interruption.
See Also
ctl_spi_unlock_bus, ctl_spi_lock_bus
CrossWorks Device Library CrossWorks Device Library
60
ctl_spi_put
Synopsis
CTL_STATUS_t ctl_spi_put(CTL_SPI_DEVICE_t *self, unsigned u);
Description
ctl_spi_put writes the single frame u to the SPI device self which must have been previously selected onto the
bus by ctl_spi_select_device.
CrossWorks Device Library CrossWorks Device Library
61
ctl_spi_put_get
Synopsis
CTL_STATUS_t ctl_spi_put_get(CTL_SPI_DEVICE_t *self, unsigned u);
Description
ctl_spi_put_get writes the single frame u to the SPI device self which must have been previously selected onto
the bus by ctl_spi_select_device and returns the data read when shifting the frame out.
CrossWorks Device Library CrossWorks Device Library
62
ctl_spi_read
Synopsis
CTL_STATUS_t ctl_spi_read(CTL_SPI_DEVICE_t *self, void *rx, size_t items);
Description
ctl_spi_read read data from the SPI device self which must have been selected onto the bus by
ctl_spi_select_device.
If the selected transfer width for the device dev is eight bits or narrower then items bytes are read from the SPI
bus to rx. If the transfer width is nine bits or wider then item shorts are read from from SPI bus and written to rx.
If rx is zero, data are read from the SPI bus and discarded if the underlying driver supports such a null transfer.
Note that some SPI drivers which use DMA may not support null transfers.
CrossWorks Device Library CrossWorks Device Library
63
ctl_spi_select_device
Synopsis
CTL_STATUS_t ctl_spi_select_device(CTL_SPI_DEVICE_t *self);
Description
ctl_spi_select_device selects the device self on the bus that it is attached to and locks access to the bus so other
devices cannot use the bus. Once the bus is locked, the device's select method is invoked.
The device remains selected until ctl_spi_deselect_device deselects the device and releases the lock on the SPI
bus.
Description
ctl_spi_select_device returns a standard status code indicating the status of setting the device's SPI protocol.
CrossWorks Device Library CrossWorks Device Library
64
ctl_spi_set_idle
Synopsis
CTL_STATUS_t ctl_spi_set_idle(CTL_SPI_DEVICE_t *self, int idle);
Description
ctl_spi_set_idle sets the SPI bus idle value when reading from the device self to idle.
Please refer to ctl_spi_set_protocol for a description of when protocol parameters are validated.
Description
ctl_spi_set_idle returns a standard status code.
See Also
ctl_spi_set_protocol
CrossWorks Device Library CrossWorks Device Library
65
ctl_spi_set_mode
Synopsis
CTL_STATUS_t ctl_spi_set_mode(CTL_SPI_DEVICE_t *self, int mode);
Description
ctl_spi_set_mode sets the SPI bus mode to use for the device self to mode.
Please refer to ctl_spi_set_protocol for a description of when protocol parameters are validated.
Description
ctl_spi_set_mode returns a standard status code.
See Also
ctl_spi_set_protocol
CrossWorks Device Library CrossWorks Device Library
66
ctl_spi_set_protocol
Synopsis
CTL_STATUS_t ctl_spi_set_protocol(CTL_SPI_DEVICE_t *self, int mode, int width, unsigned long speed, int idle);
Description
ctl_spi_set_protocol sets the SPI parameters parameters for the device self. You can set the operating
parameters of a device whether it is attached to an SPI bus or not.
Description
ctl_spi_set_protocol returns a standard status code.
Protocol parameter validation
If the device is already attached to a bus and is selected, ctl_spi_set_protocol will change the operating
parameters of the bus immediately. In this case, if the parameters are invalid or cannot be honored by the
underlying SPI bus, ctl_spi_set_protocol will return an error indication immediately. If the device is not attached
to a bus or is not selected, the parameters are stored and the bus protocol set when the device is selected. In this
case, ctl_spi_set_protocol will return a success indication, leaving validation of the parameters to the time when
the device is selected onto the bus using ctl_spi_select_device.
CrossWorks Device Library CrossWorks Device Library
67
ctl_spi_set_speed
Synopsis
CTL_STATUS_t ctl_spi_set_speed(CTL_SPI_DEVICE_t *self, unsigned long speed);
Description
ctl_spi_set_speed sets the SPI bus frequency to use for the device self to speed hertz.
Please refer to ctl_spi_set_protocol for a description of when protocol parameters are validated.
Description
ctl_spi_set_speed returns a standard status code.
See Also
ctl_spi_set_protocol
CrossWorks Device Library CrossWorks Device Library
68
ctl_spi_set_width
Synopsis
CTL_STATUS_t ctl_spi_set_width(CTL_SPI_DEVICE_t *self, int width);
Description
ctl_spi_set_width sets the SPI bus frame width to use for the device self to width.
Please refer to ctl_spi_set_protocol for a description of when protocol parameters are validated.
Description
ctl_spi_set_width returns a standard status code.
See Also
ctl_spi_set_protocol
CrossWorks Device Library CrossWorks Device Library
69
ctl_spi_unlock_bus
Synopsis
void ctl_spi_unlock_bus(CTL_SPI_BUS_t *self);
Description
ctl_spi_unlock_bus unlocks the previously-locked the SPI bus self.
CrossWorks Device Library CrossWorks Device Library
70
ctl_spi_write
Synopsis
CTL_STATUS_t ctl_spi_write(CTL_SPI_DEVICE_t *self, const void *tx, size_t items);
Description
ctl_spi_write writes data to the SPI device self which must have been previously selected onto the bus by
ctl_spi_select_device.
If the selected transfer width for the device self is eight bits or narrower then items bytes are written from tx. If
the transfer width is wider than eight bits then item shorts are written from tx.
If tx is zero, the set idle-pattern is written to the SPI device (if the the underlying driver supports such a null
transfer). Note that some SPI drivers which use DMA may not support null transfers.
CrossWorks Device Library CrossWorks Device Library
71
<ctl_sensors.h>
Overview
Interfaces to a variety of common sensor classes.
The types and functions in <ctl_sensors.h> provide a high-level set of services for a variety of common
sensor classes such as motion sensors, environmental sensors, and so on.
Each sensor class is abstracted to the essential set of features that all sensors of that class provide:
• Accelerometer: measures linear acceleration in up to three axes, with the abstract interface
CTL_ACCELEROMETER_t.
• Gyroscope: measures rotation rate in up to three axes with the abstract interface CTL_GYROSCOPE_t.
• Magnetometer: measures magnetic field strength in up to three axes, with the abstract interface
CTL_MAGNETOMETER_t.
• Pressure sensor: measures barometric air pressure, with the abstract interface
CTL_PRESSURE_SENSOR_t.
• Temperature sensor: measures temperature, with the abstract interface
CTL_TEMPERATURE_SENSOR_t.
• Light sensor: measures ambient light level, with the abstract interface CTL_LIGHT_SENSOR_t.
• Humidity sensor: measures relative humidity and, optionally, temperature, with the abstract interface
CTL_HUMIDITY_SENSOR_t.
The appropriate interface is initialized by calling the device-specific initialization code, for a particular sensor,
in the sensor library. For instance, to initialize an accelerometer interface that uses an ADXL345 acceleration
sensor, you would call adxl345_initialize_i2c. Once initialized, you can use the accelerometer-related
functions in your own code.
API Summary
Accelerometer
CTL_ACCELEROMETER_t An abstract accelerometer
ctl_accelerometer_measure Sample accelerometer axes
ctl_accelerometer_set_bandwidth Set accelerometer bandwidth
ctl_accelerometer_set_range Set accelerometer range
Gyroscope
CTL_GYROSCOPE_t An abstract gyroscope
ctl_gyroscope_measure Sample gyroscope axes
ctl_gyroscope_set_bandwidth Set gyroscope bandwidth
ctl_gyroscope_set_range Set gyroscope range
CrossWorks Device Library CrossWorks Device Library
72
Magnetometer
CTL_MAGNETOMETER_t An abstract magnetometer
ctl_magnetometer_measure Sample magnetometer axes
ctl_magnetometer_set_bandwidth Set magnetometer bandwidth
IMU
CTL_IMU_t An abstract IMU sensor collection
Temperature
CTL_TEMPERATURE_SENSOR_t An abstract temperature sensor
ctl_temperature_sensor_measure Sample temperature sensor
ctl_temperature_sensor_set_resolution Set temperature sensor resolution
Pressure Light
Humidity
CTL_HUMIDITY_SENSOR_t An abstract humidity sensor
ctl_humidity_sensor_measure Sample relative humidity
Utility
CTL_AXIS_TRANSFORMATION Single axis transformation
ctl_forward_transform_axes Apply axis transformation
ctl_generate_axis_transform Generate an axis transform from components
Pressure
CTL_PRESSURE_SENSOR_t An abstract pressure sensor
ctl_pressure_sensor_measure Sample barometric pressure
Light
CTL_LIGHT_SENSOR_t An abstract light sensor
ctl_light_sensor_measure Sample ambient light level
CrossWorks Device Library CrossWorks Device Library
73
CTL_ACCELEROMETER_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*measure)(CTL_ACCELEROMETER_s *, float *); CTL_STATUS_t (*set_range)(CTL_ACCELEROMETER_s *, int); CTL_STATUS_t (*set_bandwidth)(CTL_ACCELEROMETER_s *, float); float bias[]; float gain[]; int range; float bandwidth; void *extra; unsigned __mode;} CTL_ACCELEROMETER_t;
Description
CTL_ACCELEROMETER_t is an abstract accelerometer interface that provides clients with a means to set the
range and bandwidth of the accelerometer and to sample acceleration in up to three axes.
Structure
transport
The underlying transport for the accelerometer which provides, typically, an I2C or SPI connection to the
device and a means to read one or more registers from the device.
bias
The zero offset for the x, y, and z axes, in g. Client software may alter these to provide more accurate
calibration of the accelerometer.
gain
The gain for the x, y, and z axes, in g per count. Client software may alter these to provide more accurate
calibration of the accelerometer.
range
Current range selected for the accelerometer, in g, and is read only.
bandwidth
Current bandwidth selected for the accelerometer, in hertz, and is read only.
extra
Client-side data. You can use this to store additional information relating to the accelerometer instance.
__mode
Private working storage for the driver.
measure
Method to sample the x, y, and z axes of the accelerometer.
CrossWorks Device Library CrossWorks Device Library
74
set_range
Method to set the range of the accelerometer.
set_bandwidth
Method to set the bandwidth of the accelerometer.
CrossWorks Device Library CrossWorks Device Library
75
CTL_AXIS_TRANSFORMATION
Synopsis
typedef enum { AXIS_UNCHANGED, AXIS_POSITIVE_X, AXIS_POSITIVE_Y, AXIS_POSITIVE_Z, AXIS_NEGATED, AXIS_NEGATIVE_X, AXIS_NEGATIVE_Y, AXIS_NEGATIVE_Z} CTL_AXIS_TRANSFORMATION;
CTL_AXIS_TRANSFORMATION describes the generates an axis transform by specifying the individual
transformations for the x, y, and z axes.
CrossWorks Device Library CrossWorks Device Library
76
CTL_GYROSCOPE_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*measure)(CTL_GYROSCOPE_s *, float *); CTL_STATUS_t (*set_range)(CTL_GYROSCOPE_s *, int); CTL_STATUS_t (*set_bandwidth)(CTL_GYROSCOPE_s *, float); float gain[]; float bias[]; int range; float bandwidth; void *extra;} CTL_GYROSCOPE_t;
Description
CTL_GYROSCOPE_t is an abstract gyroscope interface that provides clients with a means to set the range and
bandwidth of the gyroscope and to sample rotation in up to three axes.
Structure
transport
The underlying transport for the gyroscope which provides, typically, an I2C or SPI connection to the device
and a means to read one or more registers from the device.
bias
The zero offset for the x, y, and z axes, in degrees per second. Client software may alter these to provide
more accurate calibration of the gyroscope.
gain
The gain for the x, y, and z axes, in degrees per second per count. Client software may alter these to provide
more accurate calibration of the gyroscope.
range
Current range selected for the gyroscope, in degrees per second, and is read only.
bandwidth
Current bandwidth selected for the gyroscope, in hertz, and is read only.
extra
Client-side data. You can use this to store additional information relating to the gyroscope instance.
measure
Method to sample the x, y, and z axes of the gyroscope.
set_range
Method to set the range of the gyroscope.
CrossWorks Device Library CrossWorks Device Library
77
set_bandwidth
Method to set the bandwidth of the gyroscope.
CrossWorks Device Library CrossWorks Device Library
78
CTL_HUMIDITY_SENSOR_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*sample)(CTL_HUMIDITY_SENSOR_s *, float *, float *);} CTL_HUMIDITY_SENSOR_t;
Description
CTL_HUMIDITY_SENSOR_t is an abstract humidity interface that provides clients with a means to sample
relative humidity.
Structure
transport
The underlying transport for the magnetometer which provides, typically, an I2C or SPI connection to the
device and a means to read one or more registers from the device.
sample
Method to read the relative humidity, and optional temperature, measured by the humidity sensor.
CrossWorks Device Library CrossWorks Device Library
79
CTL_IMU_t
Synopsis
typedef struct { CTL_ACCELEROMETER_t *accel; CTL_GYROSCOPE_t *gyro; CTL_MAGNETOMETER_t *mag;} CTL_IMU_t;
Description
CTL_IMU_t is an abstract IMU comprising accelerometer, gyroscope, and magnetometer which can be
combined for sensor fusion applications in other parts of the CrossWorks Target Library.
For instance, an accelerometer, gyroscope, and magnetometer can be fused by the AHRS library to provide a
9DOF orientation estimation. If the magnetometer member is null, the AHRS will provide a 6DOF orientation
estimation without long-term yaw correction. The tilt-compensated compass library will fuse magnetometer and
accelerometer to provide a good heading estimation irrespective of device orientation.
Structure
accel
The accelerometer instance for this sensor collection.
gyro
The gyroscope instance for this sensor collection. If the sensor collection has no gyroscope, this member
must be zero.
mag
The magnetometer instance for this sensor collection. If the sensor collection has no gyroscope, this
member must be zero.
CrossWorks Device Library CrossWorks Device Library
80
CTL_LIGHT_SENSOR_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*sample)(CTL_LIGHT_SENSOR_s *, float *);} CTL_LIGHT_SENSOR_t;
Description
CTL_LIGHT_SENSOR_t is an abstract light sensor interface that provides clients with a means to sample ambient
light level.
Structure
transport
The underlying transport for the magnetometer which provides, typically, an I2C or SPI connection to the
device and a means to read one or more registers from the device.
sample
Method to read the light level measured by the light sensor.
CrossWorks Device Library CrossWorks Device Library
81
CTL_MAGNETOMETER_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*measure)(CTL_MAGNETOMETER_s *, float *); CTL_STATUS_t (*set_bandwidth)(CTL_MAGNETOMETER_s *, float); float gain[]; float bandwidth; void *extra; unsigned __mode;} CTL_MAGNETOMETER_t;
Description
CTL_MAGNETOMETER_t is an abstract magnetometer interface that provides clients with a means to set the
range and bandwidth of the magnetometer and to sample field strength in up to three axes.
Structure
transport
The underlying transport for the magnetometer which provides, typically, an I2C or SPI connection to the
device and a means to read one or more registers from the device.
gain
The gain for the x, y, and z axes. Unlike accelerometers and gyroscopes, calibrating a magnetometer is more
complex than simply setting bias and gain for each axis independently. This member is provided for use by
the underlying magnetometer driver and client code should consider it private and no meaning should be
ascribed its values.
bandwidth
Current bandwidth selected for the magnetometer, in hertz.
extra
Client-side data. You can use this to store additional information relating to the magnetometer instance.
measure
Method to sample the x, y, and z axes of the magnetometer.
set_bandwidth
Method to set the bandwidth of the magnetometer.
CrossWorks Device Library CrossWorks Device Library
82
CTL_PRESSURE_SENSOR_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*sample)(CTL_PRESSURE_SENSOR_s *, float *, float *); unsigned __resolution;} CTL_PRESSURE_SENSOR_t;
Description
CTL_PRESSURE_SENSOR_t is an abstract pressure sensor interface that provides clients with a means to sample
barometric air pressure.
Structure
transport
The underlying transport for the magnetometer which provides, typically, an I2C or SPI connection to the
device and a means to read one or more registers from the device.
__resolution
Private member: resolution of the pressure sensor, in bits.
sample
Method to read the pressure, and optionally the temperature, measured by the pressure sensor.
CrossWorks Device Library CrossWorks Device Library
83
CTL_TEMPERATURE_SENSOR_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; CTL_STATUS_t (*set_resolution)(CTL_TEMPERATURE_SENSOR_s *, float); CTL_STATUS_t (*measure)(CTL_TEMPERATURE_SENSOR_s *, float *); float resolution; int __bits; unsigned short __mode;} CTL_TEMPERATURE_SENSOR_t;
Description
CTL_TEMPERATURE_SENSOR_t is an abstract temperature sensor interface that provides clients with a means
to sample temperature.
Structure
transport
The underlying transport for the magnetometer which provides, typically, an I2C or SPI connection to the
device and a means to read one or more registers from the device.
set_resolution
Method to set the resolution of the temperature sensor. Some temperature sensors may well not support
configurable resolution.
measure
Method to measure the temperature.
CrossWorks Device Library CrossWorks Device Library
84
ctl_accelerometer_measure
Synopsis
CTL_STATUS_t ctl_accelerometer_measure(CTL_ACCELEROMETER_t *self, float *sample);
Description
ctl_accelerometer_measure samples the accelerometer self and reports the linear acceleration in g along the x,
y, and z axes in sample[0], sample[1] and sample[2] respectively.
Return Value
ctl_accelerometer_measure returns a standard status code. If the status indicates an error, the returned sample
data is undefined.
Thread Safety
ctl_accelerometer_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
85
ctl_accelerometer_set_bandwidth
Synopsis
CTL_STATUS_t ctl_accelerometer_set_bandwidth(CTL_ACCELEROMETER_t *self, float bandwidth);
Description
ctl_accelerometer_set_bandwidth sets the bandwidth of the accelerometer self to bandwidth hertz. The
accelerometer selects the bandwidth which is closest to bandwidth, but may exceed it if range is not a setting
offered by the accelerometer.
Return Value
ctl_accelerometer_set_bandwidth returns a standard status code.
Thread Safety
ctl_accelerometer_set_bandwidth is thread-safe if the method set_bandwidth is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
86
ctl_accelerometer_set_range
Synopsis
CTL_STATUS_t ctl_accelerometer_set_range(CTL_ACCELEROMETER_t *self, int range);
Description
ctl_accelerometer_set_range sets the range of the accelerometer self to operate between plus and minus
range g. The accelerometer selects the range which is closest to range, but may exceed it if range g is not a
setting offered by the accelerometer.
After successfully executing ctl_accelerometer_set_range, the range, gain, and bias members are updated
to reflect the new setting. Note that these members are typical and are uncalibrated. You may wish to run a
calibration after setting the range to reflect the particular gain and bias coefficients for your sensor.
Return Value
ctl_accelerometer_set_range returns a standard status code.
Thread Safety
ctl_accelerometer_set_range is thread-safe if the method set_range is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
87
ctl_forward_transform_axes
Synopsis
void ctl_forward_transform_axes(int transform, float *axes);
ctl_forward_transform_axes applies the axis transformation transform to the samples pointed to by axes.
An axis transformation defines how to pick the sensor readings taken from a sensor in device mounting
coordinates and transform them to body coordinates. Given the measurement (xdevice, ydevice, zdevice) in
device coordinates, you transform this to body coordinates by applying a transformation generated by
ctl_generate_axis_transform.
Assume that a sensor requires swapping the x and y axes and negating the z axis to transform from device to
body coordinates. You would transform the coordinates using:
int transform = ctl_generate_axis_transform(AXIS_POSITIVE_Y, AXIS_POSITIVE_X, AXIS_NEGATIVE_Z);ctl_forward_transform_axes(transform, axes);
See Also
ctl_generate_axis_transform.
CrossWorks Device Library CrossWorks Device Library
88
ctl_generate_axis_transform
Synopsis
int ctl_generate_axis_transform(int x, int y, int z);
Description
ctl_generate_axis_transform generates an axis transform by specifying the individual transformations for the x,
y, and z axes. For an example of using ctl_generate_axis_transform, see ctl_forward_transform_axes.
See Also
ctl_forward_transform_axes.
CrossWorks Device Library CrossWorks Device Library
89
ctl_gyroscope_measure
Synopsis
CTL_STATUS_t ctl_gyroscope_measure(CTL_GYROSCOPE_t *self, float *sample);
Description
ctl_gyroscope_measure samples the gyroscope self and reports the clockwise rotation in degrees per second
about the x, y, and z axes in sample[0], sample[1] and sample[2] respectively.
Return Value
ctl_gyroscope_measure returns a standard status code. If the status indicates an error, the returned sample data
is undefined.
Thread Safety
ctl_gyroscope_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
90
ctl_gyroscope_set_bandwidth
Synopsis
CTL_STATUS_t ctl_gyroscope_set_bandwidth(CTL_GYROSCOPE_t *self, float bandwidth);
Description
ctl_gyroscope_set_bandwidth sets the bandwidth of the gyroscope self to bandwidth hertz. The gyroscope
selects the bandwidth which is closest to bandwidth, but may exceed it if range is not a setting offered by the
gyroscope.
Return Value
ctl_gyroscope_set_bandwidth returns a standard status code.
Thread Safety
ctl_gyroscope_set_bandwidth is thread-safe if the method set_bandwidth is thread-safe. Typically, for SPI and
I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
91
ctl_gyroscope_set_range
Synopsis
CTL_STATUS_t ctl_gyroscope_set_range(CTL_GYROSCOPE_t *self, int range);
Description
ctl_gyroscope_set_range sets the range of the gyroscope g to operate between plus and minus range degrees
per second. The gyroscope selects the range which is closest to range, but may exceed it if range degrees per
second is not a setting offered by the gyroscope.
After successfully executing ctl_gyroscope_set_range, the range, gain, and bias members are updated to
reflect the new setting. Note that these members are typical and are uncalibrated. You may wish to run a
calibration after setting the range to reflect the particular gain and bias coefficients for your sensor.
Return Value
ctl_gyroscope_set_range returns a standard status code.
Thread Safety
ctl_gyroscope_set_range is thread-safe if the method set_range is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
92
ctl_humidity_sensor_measure
Synopsis
CTL_STATUS_t ctl_humidity_sensor_measure(CTL_HUMIDITY_SENSOR_t *self, float *humidity, float *temperature);
Description
ctl_humidity_sensor_measure samples the humidity sensor self and reports the relative humidity in percent
to humidity and the temperature in degrees Celsius to temperature. If the humidity sensor is not capable
of sampling temperature, the temperature is substituted with NaN to indicate to the client that temperature
measurement is not possible.
Both humidity and temperature can be null pointers indicating that the particular measurement is not required.
Return Value
ctl_humidity_sensor_measure returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
ctl_humidity_sensor_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
93
ctl_light_sensor_measure
Synopsis
CTL_STATUS_t ctl_light_sensor_measure(CTL_LIGHT_SENSOR_t *self, float *lux);
Description
ctl_light_sensor_measure samples the light sensor self and writes the perceived ambient light level in lux to
lux[0]. If the sensor supports separate visible+IR and IR-only sensors, the light level reported by those sensors is
written to lux[1] and lux[2]. If separate readings are not supported, lux[1] and lux[2] are set to NaN.
Return Value
ctl_light_sensor_measure returns a standard status code. If the status indicates an error, the returned sample
data is undefined.
Thread Safety
ctl_light_sensor_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
94
ctl_magnetometer_measure
Synopsis
CTL_STATUS_t ctl_magnetometer_measure(CTL_MAGNETOMETER_t *self, float *sample);
Description
ctl_magnetometer_measure samples the magnetometer self and reports the measured field strength in
microtesla along about the x, y, and z axes in sample[0], sample[1] and sample[2] respectively.
The underlying magnetometer may be able to determine that the measurement along an axis has saturated. If
the magnetometer can do this, the sample for all axes are set to NaN so that client code can reject temporary
magnetic interference.
Note that the measurements returned are direct from the sensor. You will need to provide your own hard and
soft iron effect calibration and compensation code.
Return Value
ctl_magnetometer_measure returns a standard status code. If the status indicates an error, the returned sample
data is undefined.
Thread Safety
ctl_magnetometer_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
95
ctl_magnetometer_set_bandwidth
Synopsis
CTL_STATUS_t ctl_magnetometer_set_bandwidth(CTL_MAGNETOMETER_t *self, float bandwidth);
Description
ctl_magnetometer_set_bandwidth sets the bandwidth of the magnetometer self to bandwidth hertz. The
magnetometer selects the bandwidth which is closest to bandwidth, but may exceed it if range is not a setting
offered by the magnetometer.
Return Value
ctl_magnetometer_set_bandwidth returns a standard status code.
Thread Safety
ctl_magnetometer_set_bandwidth is thread-safe if the method set_bandwidth is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
96
ctl_pressure_sensor_measure
Synopsis
CTL_STATUS_t ctl_pressure_sensor_measure(CTL_PRESSURE_SENSOR_t *self, float *pressure, float *temperature);
Description
ctl_pressure_sensor_measure samples the pressure sensor self and reports the barometric pressure in pascals
to pressure and the temperature in degrees Celsius to temperature. If the pressure sensor is not capable of
sampling temperature, the temperature is substituted with NaN to indicate to the client that temperature
measurement is not possible.
Both pressure and temperature can be null pointers indicating that the particular measurement is not required.
Return Value
ctl_pressure_sensor_measure returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
ctl_pressure_sensor_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
97
ctl_temperature_sensor_measure
Synopsis
CTL_STATUS_t ctl_temperature_sensor_measure(CTL_TEMPERATURE_SENSOR_t *self, float *temperature);
Description
ctl_temperature_sensor_measure samples the temperature sensor self and reports the temperature in degrees
Celsius to temperature.
Return Value
ctl_temperature_sensor_measure returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
ctl_temperature_sensor_measure is thread-safe if the method measure is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
98
ctl_temperature_sensor_set_resolution
Synopsis
CTL_STATUS_t ctl_temperature_sensor_set_resolution(CTL_TEMPERATURE_SENSOR_t *self, float resolution);
Description
ctl_temperature_sensor_set_resolution configures the temperature sensor to deliver measurements
with a resolution of resolution degrees Celsius. For instance, standard LM75 temperature sensors deliver
measurements with a resolution of 0.5 degree Celsius, but compatibles such as the TMP100 can deliver
measurements with a resolution of 1/16th of a degree. Hence, you can configure a capable temperature sensor
for results resolved to a quarter of a degree Celsius by setting resolution to 0.25.
Return Value
ctl_temperature_sensor_set_resolution returns a standard status code.
Thread Safety
ctl_temperature_sensor_set_resolution is thread-safe if the method set_resolution is thread-safe. Typically, for
SPI and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
99
<ctl_transport.h>
Overview
Abstract device register interface.
The types and functions in <ctl_transport.h> provide a high-level means to read and write device
registers independent of the physical way in which the device is connected and addressed.
This interface is mostly used in the CrossWorks Target Library for devices connected by SPI or I2C, as many
sensors and LCD controllers are. Some sensors, such as the ADXL345, offer both I2C and SPI interfaces, selectable
using a signal. However, the high-level view of the device registers and their function remain the same in both
modes, and using an abstract register interface offered by CTL_TRANSPORT_t frees the high-level code from
concerning itself exactly how registers are read and written.
API Summary
Types
CTL_TRANSPORT_BUS_t Private transport data
CTL_TRANSPORT_t Abstract register interface
Initialization
ctl_transport_initialize_i2c Initialize an I2C transport interface
ctl_transport_initialize_spi Initialize an SPI transport interface
Read
ctl_transport_read_16b_register Read 16-bit register over transport
ctl_transport_read_24b_register Read 24-bit register over transport
ctl_transport_read_32b_register Read 32-bit register over transport
ctl_transport_read_8b_register Read 8-bit register over transport
ctl_transport_read_registers Read multiple registers over transport
Write
ctl_transport_write_16b_register Write 16-bit register over transport
ctl_transport_write_24b_register Write 24-bit register over transport
ctl_transport_write_32b_register Write 32-bit register over transport
ctl_transport_write_8b_register Write 8-bit register over transport
ctl_transport_write_registers Write multiple registers over transport
Modify
ctl_transport_rmw_16b_register Modify 16-bit register over transport
ctl_transport_rmw_24b_register Modify 24-bit register over transport
CrossWorks Device Library CrossWorks Device Library
100
ctl_transport_rmw_32b_register Modify 32-bit register over transport
ctl_transport_rmw_8b_register Modify 8-bit register over transport
Utility
ctl_transport_lock Acquire exclusive transport lock
ctl_transport_read_registers_fail Immediately fail a read from a transport
ctl_transport_read_registers_i2c Read multiple registers from an I2C transport
ctl_transport_unlock Release exclusive transport lock
ctl_transport_write_registers_fail Immediately fail a write to a transport
ctl_transport_write_registers_i2c Write multiple registers to an I2C transport
CrossWorks Device Library CrossWorks Device Library
101
CTL_TRANSPORT_BUS_t
Synopsis
typedef struct { CTL_SPI_DEVICE_t *spi; CTL_I2C_BUS_t *i2c; void *v;} CTL_TRANSPORT_BUS_t;
MEMS digital sensors are typically on SPI or I2C buses and have a register interface. But, of course, there could be
other ways to sample those registers. This structure provides private storage for the transport to run over SPI and
I2C buses.
CrossWorks Device Library CrossWorks Device Library
102
CTL_TRANSPORT_t
Synopsis
typedef struct { CTL_STATUS_t (*read_registers)(CTL_TRANSPORT_s *, int , int , void *); CTL_STATUS_t (*write_registers)(CTL_TRANSPORT_s *, int , int , const void *); unsigned char address; unsigned char big_endian; CTL_TRANSPORT_BUS_t bus; CTL_MUTEX_t *mutex;} CTL_TRANSPORT_t;
Structure
read_registers
Method to read registers using a transport interface. Clients should not call this directly.
write_registers
Method to write registers using a transport interface. Clients should not call this directly.
bus
Private member which maintains transport-related data for the bus.
big_endian
Defines the register byte order for multi-byte registers read and written over the bus.
mutex
Transport-lock mutex. This is inherited from the I2C or SPI bus when calling ctl_transport_initialize_i2c
or ctl_transport_initialize_spi. The transport is locked by read-modify-write functions to ensure that the
device register is atomically updated.
CrossWorks Device Library CrossWorks Device Library
103
ctl_transport_initialize_i2c
Synopsis
void ctl_transport_initialize_i2c(CTL_TRANSPORT_t *self, CTL_I2C_BUS_t *bus, int addr, int big_endian);
Description
ctl_transport_initialize_i2c initializes the transport self to use standard sub-addressed read and writes requests
to device registers. The device addressed is on I2C bus bus at 8-bit I2C address addr.
big_endian specifies the byte order of multi-byte registers; if big_endian is non-zero, consecutive byte registers
comprising a multi-byte register are in big-endian (network) byte order, otherwise they are in little-endian (PC)
byte order.
The methods read_registers and write_registers of the transport are initialized to
ctl_transport_read_registers_i2c and ctl_transport_write_registers_i2c. For most devices, these functions are
sufficient to read and write device registers, but some devices may require special handling, such as setting a bit
in the register sub-address to indicate incrementing addresses. If this is the case, the client can simply substitute
its replacement register access methods after the transport is initialized.
See Also
ctl_transport_read_registers_i2c, ctl_transport_write_registers_i2c
CrossWorks Device Library CrossWorks Device Library
104
ctl_transport_initialize_spi
Synopsis
void ctl_transport_initialize_spi(CTL_TRANSPORT_t *self, CTL_SPI_DEVICE_t *dev, int big_endian);
Description
ctl_transport_initialize_spi initializes the transport self to address the SPI device dev when reading and writing
registers.
big_endian specifies the byte order of multi-byte registers; if big_endian is non-zero, consecutive byte registers
comprising a multi-byte register are in big-endian (network) byte order, otherwise they are in little-endian (PC)
byte order.
The methods read_registers and write_registers of the transport are initialized to methods that immediately
return a failure because there is no consensus or standard for reading and writing device registers over SPI. In
this case, the client must provide its own register access methods after the transport is initialized.
CrossWorks Device Library CrossWorks Device Library
105
ctl_transport_lock
Synopsis
void ctl_transport_lock(CTL_TRANSPORT_t *self);
Description
ctl_transport_lock acquires the lock mutex of the transport self. If there is no mutex associated with the
transport self, ctl_transport_lock returns immediately indicating.
All locks of the transport by ctl_transport_lock must be paired with a call to ctl_transport_unlock to release the
lock.
Note
Because mutexes can be locked multiple times, you can use ctl_transport_lock to acquire the transport to issue
a sequence of transactions to the transport that cannot be interrupted by another task. However, locking a
transport realized by an I2C bus does not guarantee that other masters, in a multi-master system, are excluded
from issuing transactions on the I2C bus.
See Also
ctl_transport_unlock
CrossWorks Device Library CrossWorks Device Library
106
ctl_transport_read_16b_register
Synopsis
CTL_STATUS_t ctl_transport_read_16b_register(CTL_TRANSPORT_t *self, int reg);
Description
ctl_transport_read_16b_register reads two consecutive 8-bit registers starting at address reg from the device
associated with transport self. The two bytes read are combined to form a 16-bit value, according to the register
byte set on initialization, and is returned as the function result.
Return Value
ctl_transport_read_16b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
107
ctl_transport_read_24b_register
Synopsis
CTL_STATUS_t ctl_transport_read_24b_register(CTL_TRANSPORT_t *self, int reg);
Description
ctl_transport_read_24b_register reads three consecutive 8-bit registers starting at address reg from the device
associated with transport self. The three bytes read are combined to form a 24-bit value, according to the
register byte set on initialization, and is returned as the function result.
Return Value
ctl_transport_read_24b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
108
ctl_transport_read_32b_register
Synopsis
CTL_STATUS_t ctl_transport_read_32b_register(CTL_TRANSPORT_t *self, int reg, unsigned long *v);
Description
ctl_transport_read_32b_register reads four consecutive 8-bit registers starting at address reg from the device
associated with transport self. The four bytes read are combined to form a 24-bit value, according to the register
byte set on initialization, and assigned to the long pointed to by v.
Return Value
ctl_transport_read_32b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
109
ctl_transport_read_8b_register
Synopsis
CTL_STATUS_t ctl_transport_read_8b_register(CTL_TRANSPORT_t *self, int reg);
Description
ctl_transport_read_8b_register reads an 8-bit register at address reg from the device associated with transport
self. The register value is returned as the function result.
Return Value
If there is an error reading the register from the transport, ctl_transport_read_8b_register returns a standard
negative status code indicating the error.
CrossWorks Device Library CrossWorks Device Library
110
ctl_transport_read_registers
Synopsis
CTL_STATUS_t ctl_transport_read_registers(CTL_TRANSPORT_t *self, int reg, int n, void *data);
Description
ctl_transport_read_registers wraps a call to the device-specific register read method read_registers of the self
instance, passing the parameters through unchanged.
Whilst a client can call self's read_registers method directly, it's better style to use the wrapper function.
Return Value
ctl_transport_read_registers returns a standard status code.
Thread Safety
ctl_transport_read_registers is thread-safe if the transport self has a mutex associated with it.
ctl_transport_read_registers ensures an atomic update of the register by locking the transport before writing
the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
111
ctl_transport_read_registers_fail
Synopsis
CTL_STATUS_t ctl_transport_read_registers_fail(CTL_TRANSPORT_t *self, int reg, int n, void *data);
Description
ctl_transport_read_registers_fail returns immediately indicating an unsupported operation. You can use this
function to replace the default read_registers method after initializing a transport if reading from registers is not
appropriate for the underlying device.
Return Value
ctl_transport_read_registers_fail returns a fail status code.
CrossWorks Device Library CrossWorks Device Library
112
ctl_transport_read_registers_i2c
Synopsis
CTL_STATUS_t ctl_transport_read_registers_i2c(CTL_TRANSPORT_t *self, int reg, int n, void *data);
Description
ctl_transport_read_registers_i2c reads multiple registers from an I2C transport and is the default method
installed into read_registers by ctl_transport_initialize_i2c.
The implementation of this depends upon ctl_i2c_write_read to issue a correct I2C bus transaction. A request to
read n bytes from registers starting at reg on the I2C transport self is constructed, transacted over the bus, and
the completion status returned.
The request to the I2C slave device is constructed which:
• transmits a start bit;
• transmits a Slave Address Write to select the I2C slave device;
• transmits a byte reg to select the subaddress to commence reading from;
• transmits a repeated start bit;
• transmits a Slave Address Read to select the same I2C slave device;
• receives a block of n bytes into data;
• transmits a stop bit.
Return Value
ctl_transport_read_registers_i2c returns a standard status code.
Thread Safety
ctl_transport_read_registers_i2c is thread-safe if the transport self has a mutex associated with it.
ctl_transport_read_registers_i2c ensures an atomic update of the register by locking the transport before
writing the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
113
ctl_transport_rmw_16b_register
Synopsis
CTL_STATUS_t ctl_transport_rmw_16b_register(CTL_TRANSPORT_t *self, int reg, unsigned mask, unsigned value);
Description
ctl_transport_rmw_16b_register reads, updates, and writes two consecutive 8-bit registers starting at address
reg on the device associated with transport self. The register is modified by replacing existing bits with new bits
from value where the the corresponding bits in mask are non-zero.
The value written back to the register is:
(not mask and value-of-register) or (value and mask).
Return Value
ctl_transport_rmw_16b_register returns a standard status code.
Thread Safety
ctl_transport_rmw_16b_register is thread-safe if the transport self has a mutex associated with it.
ctl_transport_rmw_16b_register ensures an atomic update of the register by locking the transport before
reading the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
114
ctl_transport_rmw_24b_register
Synopsis
CTL_STATUS_t ctl_transport_rmw_24b_register(CTL_TRANSPORT_t *self, int reg, unsigned long mask, unsigned long value);
Description
ctl_transport_rmw_24b_register reads, updates, and writes three consecutive 8-bit registers starting at address
reg on the device associated with transport self. The register is modified by replacing existing bits with new bits
from value where the the corresponding bits in mask are non-zero.
The value written back to the register is:
(not mask and value-of-register) or (value and mask).
Return Value
ctl_transport_rmw_24b_register returns a standard status code.
Thread Safety
ctl_transport_rmw_24b_register is thread-safe if the transport self has a mutex associated with it.
ctl_transport_rmw_24b_register ensures an atomic update of the register by locking the transport before
reading the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
115
ctl_transport_rmw_32b_register
Synopsis
CTL_STATUS_t ctl_transport_rmw_32b_register(CTL_TRANSPORT_t *self, int reg, unsigned long mask, unsigned long value);
Description
ctl_transport_rmw_32b_register reads, updates, and writes four consecutive 8-bit registers starting at address
reg on the device associated with transport self. The register is modified by replacing existing bits with new bits
from value where the the corresponding bits in mask are non-zero.
The value written back to the register is:
(not mask and value-of-register) or (value and mask).
Return Value
ctl_transport_rmw_32b_register returns a standard status code.
Thread Safety
ctl_transport_rmw_32b_register is thread-safe if the transport self has a mutex associated with it.
ctl_transport_rmw_32b_register ensures an atomic update of the register by locking the transport before
reading the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
116
ctl_transport_rmw_8b_register
Synopsis
CTL_STATUS_t ctl_transport_rmw_8b_register(CTL_TRANSPORT_t *self, int reg, unsigned mask, unsigned value);
Description
ctl_transport_rmw_8b_register reads, updates, and writes the 8-bit register at address reg on the device
associated with transport self. The register is modified by replacing existing bits with new bits from value where
the the corresponding bits in mask are non-zero.
The value written back to the register is:
(not mask and value-of-register) or (value and mask).
Return Value
ctl_transport_rmw_8b_register returns a standard status code.
Thread Safety
ctl_transport_rmw_8b_register is thread-safe if the transport self has a mutex associated with it.
ctl_transport_rmw_8b_register ensures an atomic update of the register by locking the transport before
reading the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
117
ctl_transport_unlock
Synopsis
void ctl_transport_unlock(CTL_TRANSPORT_t *self);
Description
ctl_transport_unlock releases a mutex that was successfully locked using ctl_transport_lock. If there is no
mutex associated with the transport self, ctl_transport_unlock returns immediately. It is an error to release a
lock that was not acquired successfully.
See Also
ctl_transport_lock
CrossWorks Device Library CrossWorks Device Library
118
ctl_transport_write_16b_register
Synopsis
CTL_STATUS_t ctl_transport_write_16b_register(CTL_TRANSPORT_t *self, int reg, int value);
Description
ctl_transport_write_16b_register writes value to two consecutive 8-bit registers starting at address reg on the
device associated with transport self. The registers are written in the byte order specified on initialization of the
transport.
Return Value
ctl_transport_write_16b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
119
ctl_transport_write_24b_register
Synopsis
CTL_STATUS_t ctl_transport_write_24b_register(CTL_TRANSPORT_t *self, int reg, unsigned long value);
Description
ctl_transport_write_24b_register writes value to three consecutive 8-bit registers starting at address reg on the
device associated with transport self. The registers are written in the byte order specified on initialization of the
transport.
Return Value
ctl_transport_write_24b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
120
ctl_transport_write_32b_register
Synopsis
CTL_STATUS_t ctl_transport_write_32b_register(CTL_TRANSPORT_t *self, int reg, unsigned long value);
Description
ctl_transport_write_32b_register writes value to four consecutive 8-bit registers starting at address reg on the
device associated with transport self. The registers are written in the byte order specified on initialization of the
transport.
Return Value
ctl_transport_write_32b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
121
ctl_transport_write_8b_register
Synopsis
CTL_STATUS_t ctl_transport_write_8b_register(CTL_TRANSPORT_t *self, int reg, int value);
Description
ctl_transport_write_8b_register writes value to the 8-bit register at address reg on the device associated with
transport self.
Return Value
ctl_transport_write_8b_register returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
122
ctl_transport_write_registers
Synopsis
CTL_STATUS_t ctl_transport_write_registers(CTL_TRANSPORT_t *self, int reg, int n, const void *data);
Description
ctl_transport_write_registers wraps a call to the device-specific register write method write_registers of the
self instance, passing the parameters through unchanged.
Whilst a client can call the self's write_registers method directly, it's better style to use the wrapper function.
Return Value
ctl_transport_write_registers returns a standard status code.
Thread Safety
ctl_transport_write_registers is thread-safe if the transport self has a mutex associated with it.
ctl_transport_write_registers ensures an atomic update of the register by locking the transport before writing
the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
123
ctl_transport_write_registers_fail
Synopsis
CTL_STATUS_t ctl_transport_write_registers_fail(CTL_TRANSPORT_t *self, int reg, int n, const void *data);
Description
ctl_transport_write_registers_fail returns immediately indicating an unsupported operation. You can use this
function to replace the default write_registers method after initializing a transport if writing to registers is not
appropriate for the underlying device.
Return Value
ctl_transport_write_registers_fail returns a fail status code.
CrossWorks Device Library CrossWorks Device Library
124
ctl_transport_write_registers_i2c
Synopsis
CTL_STATUS_t ctl_transport_write_registers_i2c(CTL_TRANSPORT_t *self, int reg, int n, const void *data);
Description
ctl_transport_write_registers_i2c writes multiple registers to an I2C transport and is the default method
installed into write_registers by ctl_transport_initialize_i2c.
The implementation of this depends upon ctl_i2c_write to issue a correct I2C bus transaction. A request to
write n bytes to registers starting at reg on the I2C transport self is constructed, transacted over the bus, and the
completion status returned.
The request to the I2C slave device is constructed which:
• transmits a start bit;
• transmits a Slave Address Write to select the I2C slave device;
• transmits a byte reg to select the subaddress to commence writing to;
• transmits a block of n bytes from data;
• transmits a stop bit.
Note
The implementation of ctl_transport_write_registers_i2c restricts the number of bytes written to 32.
Return Value
ctl_transport_write_registers_i2c returns a standard status code.
Thread Safety
ctl_transport_write_registers_i2c is thread-safe if the transport self has a mutex associated with it.
ctl_transport_write_registers_i2c ensures an atomic update of the register by locking the transport before
writing the register and unlocking it after writing the register.
CrossWorks Device Library CrossWorks Device Library
125
<ctl_uart.h>
Overview
Abstract UART interface.
The types and functions in <ctl_uart.h> provide a high-level set of services for an application to read and
write data over one or more SPI buses. The UART interface in this library is abstract in the sense that there is no
concrete implementation within the library. Rather, implementations of the UART interface are offered by the
many driver packages that you can install as a CrossWorks package.
To see examples of this API in use, please install the CrossWorks demonstration package for your particular
board and open up its contents in the Project Explorer and take a look around.
API Summary
I/O functions
ctl_uart_getc Read character from UART
ctl_uart_getc_nb Read character from UART (non-blocking)
ctl_uart_putc Write character to UART
ctl_uart_puts Write string to UART
CrossWorks Device Library CrossWorks Device Library
126
ctl_uart_getc
Synopsis
int ctl_uart_getc(CTL_UART_t *self);
Description
ctl_uart_getc reads one character from the UART self. This function will block until a character is available to
read.
Return Value
ctl_uart_getc returns the character read from the UART.
CrossWorks Device Library CrossWorks Device Library
127
ctl_uart_getc_nb
Synopsis
int ctl_uart_getc_nb(CTL_UART_t *self);
Description
ctl_uart_getc_nb reads one character from the UART self. If no character is available,
Description
ctl_uart_getc_nb returns a negative value.
Return Value
ctl_uart_getc_nb returns the character read from the UART or a negative value if none is available.
CrossWorks Device Library CrossWorks Device Library
128
ctl_uart_putc
Synopsis
void ctl_uart_putc(CTL_UART_t *self, char c);
Description
ctl_uart_putc writes the character c to the UART self.
Note
The implementation of ctl_uart_putc passes the character c directly to the driver layer without translation. The
driver implementation may elect to translate the C newline character '\n' as a CR+LF combination.
CrossWorks Device Library CrossWorks Device Library
129
ctl_uart_puts
Synopsis
void ctl_uart_puts(CTL_UART_t *self, const char *str);
Description
ctl_uart_puts writes the null-terminated string str to to the UART self.
CrossWorks Device Library CrossWorks Device Library
130
<adc101s021.h>
API Summary
Functions
adc101s021_init Initialize
adc101s021_measure_raw Initialize
CrossWorks Device Library CrossWorks Device Library
131
adc101s021_init
Synopsis
void adc101s021_init(CTL_SPI_DEVICE_t *d);
CrossWorks Device Library CrossWorks Device Library
132
adc101s021_measure_raw
Synopsis
unsigned adc101s021_measure_raw(CTL_SPI_DEVICE_t *d);
CrossWorks Device Library CrossWorks Device Library
133
<ltc2309.h>
Overview
Driver for a Linear Technology LTC2309 analog to digital converter.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.linear.com/product/LTC2309
Datasheet
http://cds.linear.com/docs/en/datasheet/2309fd.pdf
Test hardware
This code has been tested using a Libelium Raspberry Pi to Arduino shields connection bridge:
http://www.cooking-hacks.com/index.php/Raspberry-pi-to-arduino-shield-connection-bridge.html
Installed on a Raspberry Pi:
http://www.raspberrypi.org/
API Summary
Macros
LTC2309_I2C_ADDR LTC2309 8-bit I2C address selected by AD1:0
Initialization
ltc2309_init_i2c Initialize device on I2C bus
Control
ltc2309_sample_differential_bipolar Sample channel in differential pair mode, bipolar
ltc2309_sample_differential_unipolar Sample channel in differential pair mode, unipolar
ltc2309_sample_single_ended_bipolar Sample channel in single-ended mode, bipolar
ltc2309_sample_single_ended_unipolar Sample channel in single-ended mode, unipolar
CrossWorks Device Library CrossWorks Device Library
134
LTC2309_I2C_ADDR
Synopsis
#define LTC2309_I2C_ADDR(ADx) (0x10 + 2*(ADx))
See Also
ltc2309_init_i2c
CrossWorks Device Library CrossWorks Device Library
135
ltc2309_init_i2c
Synopsis
CTL_STATUS_t ltc2309_init_i2c(CTL_ADC_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
ltc2309_init_i2c initializes the LTC2309 self on I2C bus bus using the 8-bit I2C address addr.
Return Value
ltc2309_init_i2c returns a standard status code.
Thread Safety
ltc2309_init_i2c is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
136
ltc2309_sample_differential_bipolar
Synopsis
CTL_STATUS_t ltc2309_sample_differential_bipolar(LTC2309_ADC_t *self, int channel, float *sample);
Description
ltc2309_sample_differential_bipolar samples channel channel and channel xor 1 in bipolar differential mode
with channel channel as the positive input and channel channel xor 1 as the negative input.
The object pointed to by sample is written to a value between −1 and +1 (inclusive) that represents the value
sampled.
Return Value
ltc2309_sample_differential_bipolar returns a standard status code.
Thread Safety
ltc2309_sample_differential_bipolar is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
137
ltc2309_sample_differential_unipolar
Synopsis
CTL_STATUS_t ltc2309_sample_differential_unipolar(LTC2309_ADC_t *self, int channel, float *sample);
Description
ltc2309_sample_differential_unipolar samples channel channel and channel xor 1 in unipolar differential
mode with channel channel as the positive input and channel channel xor 1 as the negative input.
The object pointed to by sample is written to a value between 0 and +1 (inclusive) that represents the value
sampled.
Return Value
ltc2309_sample_differential_unipolar returns a standard status code.
Thread Safety
ltc2309_sample_differential_unipolar is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
138
ltc2309_sample_single_ended_bipolar
Synopsis
CTL_STATUS_t ltc2309_sample_single_ended_bipolar(LTC2309_ADC_t *self, int channel, float *sample);
Description
ltc2309_sample_single_ended_bipolar samples channel channel in single-ended mode using COM as the
negative terminal. The object pointed to by sample is written to a value between −1 and +1 (inclusive) that
represents the value sampled.
Return Value
ltc2309_sample_single_ended_bipolar returns a standard status code.
Thread Safety
ltc2309_sample_single_ended_bipolar is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
139
ltc2309_sample_single_ended_unipolar
Synopsis
CTL_STATUS_t ltc2309_sample_single_ended_unipolar(CTL_ADC_t *self, int channel, float *sample);
Description
ltc2309_sample_single_ended_unipolar samples channel channel in single-ended mode using COM as the
negative terminal. The object pointed to by sample is written to a value between 0 and 1 (inclusive) that
represents the value sampled.
Return Value
ltc2309_sample_single_ended_unipolar returns a standard status code.
Thread Safety
ltc2309_sample_single_ended_unipolar is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
140
<mcp23016.h>
Overview
Driver for a Microchip MCP23016 16-bit I2C bus expander..
The MCP23016 is a 16-bit port expander where each of the bits can function as either an input or an output.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en010412
Datasheet
http://www.microchip.com/downloads/en/DeviceDoc/20090C.pdf
Test hardware
This code has been tested using a SolderCore controlling a SenseCore.
http://www.soldercore.com/
API Summary
Constants
MCP23016_I2C_ADDR 8-bit I2C address for MC23016
Functions
mcp23016_initialize_i2c Initialize bus expander on I2C bus
CrossWorks Device Library CrossWorks Device Library
141
MCP23016_I2C_ADDR
Synopsis
#define MCP23016_I2C_ADDR(X) ((X)*2 + 0x40)
Description
MCP23016_I2C_ADDR returns the 8-bit I2C address for the MC23016 for the address configuration signals
AD0, AD1, and AD2 presented in X. AD0 is the least significant bit and AD2 is the most significant bit, hence 0x6
represents AD2=1, AD1=1, AD0=0.
The address is calculated as 0x40 + (X << 1).
CrossWorks Device Library CrossWorks Device Library
142
mcp23016_initialize_i2c
Synopsis
CTL_STATUS_t mcp23016_initialize_i2c(CTL_PARALLEL_BUS_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mcp23016_initialize_i2c initializes the parallel bus driver self with methods to control an MCP23016 attached to
I2C bus bus at 8-bit I2C address addr. The MCP23016 is initialized to all-input mode. The parallel bus self inherits
any mutex associated with the bus bus.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
mcp23016_initialize_i2c returns a standard status code.
Thread Safety
mcp23016_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
143
<mcp23x08.h>
Overview
Driver for a Microchip MCP23008 (I2C) or MCP23S08 (SPI) bus expander..
The MCP23008 is a 8-bit I2C port expander and the MCP23S08 is an 8-bit SPI port expander where each of the
bits can function as either an input or an output.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
MCP23008
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en021393
MCP23S08
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en021817
Datasheet
http://www.microchip.com/downloads/en/DeviceDoc/21919e.pdf
Test hardware
This code has been tested using a SolderCore controlling a SenseCore.
http://www.soldercore.com/
API Summary
Constants
MCP23008_I2C_ADDR 8-bit I2C address for MC23008
Functions
mcp23x08_initialize_i2c Initialize bus expander on I2C bus
mcp23x08_initialize_spi Initialize bus expander on SPI bus
CrossWorks Device Library CrossWorks Device Library
144
MCP23008_I2C_ADDR
Synopsis
#define MCP23008_I2C_ADDR(ADx) (0x40 + 2*(ADx))
Description
MCP23008_I2C_ADDR returns the 8-bit I2C address for the MC23008 for the address configuration signals AD0,
AD1, and AD2 presented in ADx. AD0 is the least significant bit and AD2 is the most significant bit, hence 0x6
represents AD2=1, AD1=1, AD0=0.
CrossWorks Device Library CrossWorks Device Library
145
mcp23x08_initialize_i2c
Synopsis
CTL_STATUS_t mcp23x08_initialize_i2c(CTL_PARALLEL_BUS_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mcp23x08_initialize_i2c initializes the parallel bus driver self with methods to control an MCP23008 attached to
I2C bus bus at 8-bit I2C address addr. The MCP23008 is initialized to all-input mode. The parallel bus self inherits
any mutex associated with the bus bus.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
mcp23x08_initialize_i2c returns a standard status code.
Thread Safety
mcp23x08_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
146
mcp23x08_initialize_spi
Synopsis
CTL_STATUS_t mcp23x08_initialize_spi(CTL_PARALLEL_BUS_t *bus, CTL_SPI_DEVICE_t *dev);
Description
mcp23x08_initialize_spi initializes the parallel bus driver self with methods to control an MCP23S08 on the SPI
bus associated with dev. The MCP23S08 is initialized to all-input mode. The parallel bus self inherits any mutex
associated with the SPI bus that dev is attached to.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
mcp23x08_initialize_spi returns a standard status code.
Thread Safety
mcp23x08_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
147
<mcp23x17.h>
Overview
Driver for a Microchip MCP23017 (I2C) or MCP23S17 (SPI) bus expander..
The MCP23017 is a 16-bit I2C port expander and the MCP23S17 is an 16-bit SPI port expander where each of the
bits can function as either an input or an output.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
MCP23017
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en023499
MCP23S17
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en023500
Datasheet
http://www.microchip.com/downloads/en/DeviceDoc/21952b.pdf
Test hardware
This code has been tested using a SolderCore controlling a SenseCore.
http://www.soldercore.com/
API Summary
Constants
MCP23017_I2C_ADDR 8-bit I2C address for MCP23017
Functions
mcp23x17_initialize_i2c Initialize bus expander on I2C bus
mcp23x17_initialize_spi Initialize bus expander on SPI bus
CrossWorks Device Library CrossWorks Device Library
148
MCP23017_I2C_ADDR
Synopsis
#define MCP23017_I2C_ADDR(ADx) (0x40 + 2*(ADx))
Description
MCP23017_I2C_ADDR returns the 8-bit I2C address for the MCP23017 for the address configuration signals
AD0, AD1, and AD2 presented in X. AD0 is the least significant bit and AD2 is the most significant bit, hence 0x6
represents AD2=1, AD1=1, AD0=0.
The address is calculated as 0x40 + 2*ADx).
CrossWorks Device Library CrossWorks Device Library
149
mcp23x17_initialize_i2c
Synopsis
CTL_STATUS_t mcp23x17_initialize_i2c(CTL_PARALLEL_BUS_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mcp23x17_initialize_i2c initializes the parallel bus driver self with methods to control an MCP23017 attached to
I2C bus bus at 8-bit I2C address addr. The MCP23017 is initialized to all-input mode. The parallel bus self inherits
any mutex associated with the bus bus.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
mcp23x17_initialize_i2c returns a standard status code.
Thread Safety
mcp23x17_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
150
mcp23x17_initialize_spi
Synopsis
CTL_STATUS_t mcp23x17_initialize_spi(CTL_PARALLEL_BUS_t *bus, CTL_SPI_DEVICE_t *dev);
Description
mcp23x17_initialize_spi initializes the parallel bus driver self with methods to control an MCP23S17 on the SPI
bus associated with dev. The MCP23S17 is initialized to all-input mode. The parallel bus self inherits any mutex
associated with the SPI bus that dev is attached to.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
mcp23x17_initialize_spi returns a standard status code.
Thread Safety
mcp23x17_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
151
<pca9532.h>
Overview
Driver for an NXP PCA9532 16-bit port expander / LED driver.
The PCA9532 is an 8-bit port expander where each of the bits can function as either an input or an output.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.nxp.com/products/lighting_driver_and_controller_ics/i2c_led_display_control/series/
PCA9532.html
Datasheet
http://www.nxp.com/documents/data_sheet/PCA9532.pdf
Test hardware
This code has been tested using an Embedded Artists base board with LPC1788-OEM module.
API Summary
Setup
PCA9532_I2C_ADDR 8-bit I2C address for PCA9532
pca9532_initialize_i2c Initialize bus expander on I2C bus
LEDs
pca9532_led_mode Get LED mode
pca9532_set_duty_cycle Set channel duty cycle
pca9532_set_led_mode Set LED mode
pca9532_set_pwm_frequency Set PWM frequency
CrossWorks Device Library CrossWorks Device Library
152
PCA9532_I2C_ADDR
Synopsis
#define PCA9532_I2C_ADDR(ADx) (0xc0 + 2*(ADx))
Description
PCA9532_I2C_ADDR returns the 8-bit I2C address for the PCA9532 for the address configuration signals AD0,
AD1, and AD2 presented in ADx. AD0 is the least significant bit and AD2 is the most significant bit, hence 0x6
represents AD2=1, AD1=1, AD0=0.
The address is calculated as 0xc0 + 2*ADx.
CrossWorks Device Library CrossWorks Device Library
153
pca9532_initialize_i2c
Synopsis
CTL_STATUS_t pca9532_initialize_i2c(PCA9532_DRIVER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
pca9532_initialize_i2c initializes the parallel bus driver self with methods to control a PCA9532 attached to I2C
bus bus at 8-bit I2C address addr. The PCA9532 is initialized to all-input mode. The parallel bus self inherits any
mutex associated with the bus bus.
Bits 0 through 7 assigned to port 0 and bits 8 through 15 are assigned to port 1.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
pca9532_initialize_i2c returns a standard status code.
Thread Safety
pca9532_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
154
pca9532_led_mode
Synopsis
CTL_STATUS_t pca9532_led_mode(PCA9532_DRIVER_t *self, int index);
Description
pca9532_led_mode reads the mode of LED index.
Return Value
pca9532_led_mode returns an extended status code; non-negative values are the LED mode.
Thread Safety
pca9532_led_mode is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
155
pca9532_set_duty_cycle
Synopsis
CTL_STATUS_t pca9532_set_duty_cycle(PCA9532_DRIVER_t *self, int channel, float ratio);
Description
pca9532_set_duty_cycle sets the duty ratio of channel channel of the LED driver self to ratio. channel is 0 or 1
to select between the two channels and ratio is between 0 and 1 (inclusive) to set the duty ratio.
Note that a duty ratio of 1 will turn the LED on and 0 will turn it off, and at the pins a duty ratio of 1 outputs DC
low and a duty ratio of 0 outputs DC high.
Return Value
pca9532_set_duty_cycle returns a standard status code.
Thread Safety
pca9532_set_duty_cycle is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
156
pca9532_set_led_mode
Synopsis
CTL_STATUS_t pca9532_set_led_mode(PCA9532_DRIVER_t *self, int index, PCA9532_OUTPUT_MODE_t mode);
Description
pca9532_set_led_mode writes the mode of LED index to mode which can be used to set the LED to blink.
Return Value
pca9532_set_led_mode returns a standard status code.
Thread Safety
pca9532_set_led_mode is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
157
pca9532_set_pwm_frequency
Synopsis
CTL_STATUS_t pca9532_set_pwm_frequency(PCA9532_DRIVER_t *self, int channel, float frequency);
Description
pca9532_set_pwm_frequency sets the PWM frequency of channel channel of the LED driver self to frequency
hertz. channel is 0 or 1 to select between the two channels.
Return Value
pca9532_set_pwm_frequency returns a standard status code.
Thread Safety
pca9532_set_pwm_frequency is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
158
<pca9672.h>
Overview
Driver for an NXP PCA9672 8-bit port expander.
The PCA9672 is an 8-bit port expander where each of the bits can function as either an input or an output.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/series/
PCA9672.html
Datasheet
http://www.nxp.com/documents/data_sheet/PCA9672.pdf
Test hardware
This code has been tested using an LPC800-MAX.
API Summary
Functions
pca9672_initialize_i2c Initialize bus expander on I2C bus
CrossWorks Device Library CrossWorks Device Library
159
pca9672_initialize_i2c
Synopsis
CTL_STATUS_t pca9672_initialize_i2c(CTL_PARALLEL_BUS_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
pca9672_initialize_i2c initializes the parallel bus driver self with methods to control a PCA9672 attached to I2C
bus bus at 8-bit I2C address addr. The PCA9672 is initialized to all-input mode. The parallel bus self inherits any
mutex associated with the bus bus.
Bits 0 through 7 assigned to port 0 and bits 8 through 15 are assigned to port 1.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
pca9672_initialize_i2c returns a standard status code.
Thread Safety
pca9672_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
160
<pcf8575.h>
Overview
Driver for an NXP PCF8575 16-bit port expander.
The PCF8575 is a 16-bit port expander where each of the bits can function as either an input or an output.
The PCF8575 is functionally identical to the PC8575, PCF8575C, PCF8574, PCA9535, PCA9555, and probably
many others.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/series/
PCA8575.html
Datasheet
http://www.nxp.com/documents/data_sheet/PCF8575.pdf
Test hardware
This code has been tested using a SolderCore controlling a SenseCore.
http://www.soldercore.com/
API Summary
Constants
PCF8575_I2C_ADDR 8-bit I2C address for PCF8575
Functions
pcf8575_initialize_i2c Initialize bus expander on I2C bus
CrossWorks Device Library CrossWorks Device Library
161
PCF8575_I2C_ADDR
Synopsis
#define PCF8575_I2C_ADDR(ADx) (0x40 + 2*(ADx))
Description
PCF8575_I2C_ADDR returns the 8-bit I2C address for the PCF8575 for the address configuration signals AD0,
AD1, and AD2 presented in ADx. AD0 is the least significant bit and AD2 is the most significant bit, hence 0x6
represents AD2=1, AD1=1, AD0=0.
The address is calculated as 0x40 + 2*ADx.
CrossWorks Device Library CrossWorks Device Library
162
pcf8575_initialize_i2c
Synopsis
CTL_STATUS_t pcf8575_initialize_i2c(CTL_PARALLEL_BUS_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
pcf8575_initialize_i2c initializes the parallel bus driver self with methods to control a PCF8575 attached to I2C
bus bus at 8-bit I2C address addr. The PCF8575 is initialized to all-input mode. The parallel bus self inherits any
mutex associated with the bus bus.
Bits 0 through 7 assigned to port 0 and bits 8 through 15 are assigned to port 1.
Once the parallel bus interface is initialized, you can use all standard parallel bus methods from the sensor API
on the interface.
Return Value
pcf8575_initialize_i2c returns a standard status code.
Thread Safety
pcf8575_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_bus.h>
CrossWorks Device Library CrossWorks Device Library
163
<ltc6904.h>
Overview
Driver for a Linear Technology LTC6904 digital oscillator.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.linear.com/product/LTC6904
Datasheet
http://cds.linear.com/docs/Datasheet/69034fe.pdf
Test hardware
This code has been tested using a Gravitech I2C-OSC module:
http://www.gravitech.us/i2c1kto68pro.html
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Constants
LTC6904_I2C_ADDR_ADR0 8-bit I2C address with ADR=0
LTC6904_I2C_ADDR_ADR1 8-bit I2C address with ADR=1
LTC6904_MODE_CLK_OFF_nCLK_ON CLK off, nCLK on mode
LTC6904_MODE_CLK_ON_nCLK_OFF CLK on, nCLK off mode
LTC6904_MODE_CLK_ON_nCLK_ON CLK and nCLK on mode
LTC6904_MODE_POWER_DOWN Powered down mode
Types
LTC6904_OSCILLATOR_t LTC6904 state
Initialization
CrossWorks Device Library CrossWorks Device Library
164
ltc6904_init_i2c Initialize device on I2C bus
Control
ltc6904_set_frequency Set oscillator output frequency
ltc6904_set_mode Set output mode
Status
ltc6904_get_selected_frequency Get selected oscillator frequency
CrossWorks Device Library CrossWorks Device Library
165
LTC6904_I2C_ADDR_ADR0
Synopsis
#define LTC6904_I2C_ADDR_ADR0 0x2E
Description
LTC6904_I2C_ADDR_ADR0 is the selected 8-bit I2C address of the LTC6904 oscillator when ADR=0.
See Also
ltc6904_init_i2c
CrossWorks Device Library CrossWorks Device Library
166
LTC6904_I2C_ADDR_ADR1
Synopsis
#define LTC6904_I2C_ADDR_ADR1 0x2C
Description
LTC6904_I2C_ADDR_ADR1 is the selected 8-bit I2C address of the LTC6904 oscillator when ADR=1.
See Also
ltc6904_init_i2c
CrossWorks Device Library CrossWorks Device Library
167
LTC6904_MODE_CLK_OFF_nCLK_ON
Synopsis
#define LTC6904_MODE_CLK_OFF_nCLK_ON 0x01
Description
LTC6904_MODE_CLK_OFF_nCLK_ON mode drives nCLK from the oscillator and does not drive CLK.
See Also
ltc6904_set_mode
CrossWorks Device Library CrossWorks Device Library
168
LTC6904_MODE_CLK_ON_nCLK_OFF
Synopsis
#define LTC6904_MODE_CLK_ON_nCLK_OFF 0x02
Description
LTC6904_MODE_CLK_ON_nCLK_OFF mode drives CLK from the oscillator and does not drive nCLK.
See Also
ltc6904_set_mode
CrossWorks Device Library CrossWorks Device Library
169
LTC6904_MODE_CLK_ON_nCLK_ON
Synopsis
#define LTC6904_MODE_CLK_ON_nCLK_ON 0x00
Description
LTC6904_MODE_CLK_ON_nCLK_ON mode drives both CLK and nCLK from the oscillator with nCLK = −CLK.
See Also
ltc6904_set_mode
CrossWorks Device Library CrossWorks Device Library
170
LTC6904_MODE_POWER_DOWN
Synopsis
#define LTC6904_MODE_POWER_DOWN 0x03
Description
LTC6904_MODE_POWER_DOWN mode powers down the oscillator.
See Also
ltc6904_set_mode
CrossWorks Device Library CrossWorks Device Library
171
LTC6904_OSCILLATOR_t
Synopsis
typedef struct { CTL_TRANSPORT_t transport; unsigned short __dac; unsigned char __octave; unsigned char __mode; unsigned char __config;} LTC6904_OSCILLATOR_t;
Description
LTC6904_OSCILLATOR_t contains the internal state of the LTC6904 driver and should be considered
inaccessible by the client.
CrossWorks Device Library CrossWorks Device Library
172
ltc6904_get_selected_frequency
Synopsis
float ltc6904_get_selected_frequency(LTC6904_OSCILLATOR_t *self);
Description
ltc6904_get_selected_frequency returns the selected oscillator frequency in hertz, derived from the internal
octave and DAC select bits. This is the datasheet "true" oscillator frequency nearest to the frequency requested
by ltc6904_set_frequency.
Return Value
ltc6904_get_selected_frequency returns a standard status code.
Thread Safety
ltc6904_get_selected_frequency is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
ltc6904_set_frequency.
CrossWorks Device Library CrossWorks Device Library
173
ltc6904_init_i2c
Synopsis
CTL_STATUS_t ltc6904_init_i2c(LTC6904_OSCILLATOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
ltc6904_init_i2c initializes the LTC6904 self on I2C bus bus using the 8-bit I2C address addr.
Return Value
ltc6904_init_i2c returns a standard status code.
Thread Safety
ltc6904_init_i2c is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
174
ltc6904_set_frequency
Synopsis
CTL_STATUS_t ltc6904_set_frequency(LTC6904_OSCILLATOR_t *self, float frequency);
Description
ltc6904_set_frequency sets the oscillator self to the frequency nearest frequency hertz. You can read the
oscillator frequency selected by ltc6904_set_frequency using ltc6904_get_selected_frequency.
Return Value
ltc6904_set_frequency returns a standard status code.
Thread Safety
ltc6904_set_frequency is thread-safe if the transport member in self is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
ltc6904_get_selected_frequency.
CrossWorks Device Library CrossWorks Device Library
175
ltc6904_set_mode
Synopsis
CTL_STATUS_t ltc6904_set_mode(LTC6904_OSCILLATOR_t *self, int mode);
Description
ltc6904_set_mode sets the oscillator output mode to mode, which is one of the constants described in the
Constants section.
Return Value
ltc6904_set_mode returns a standard status code.
Thread Safety
ltc6904_set_mode is thread-safe if the transport member in self is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
176
<adt7410.h>
Overview
Driver for an ADT7410 temperature sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.analog.com/en/mems-sensors/digital-temperature-sensors/adt7410/products/product.html
Datasheet
http://www.analog.com/static/imported-files/data_sheets/ADT7410.pdf
Test hardware
This code has been tested using an ADT7410 on a breakout board hand-wired to a SolderCore.
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Resolution (°C) 0.0625 (default), 0.0078125
Communication up to 3.4 MHz (I2C) and 5 MHz (SPI)
API Summary
Macros
ADT7410_I2C_ADDR ADT7410 8-bit I2C address selected by A1:A0
Functions
adt7410_initialize_i2c Initialize ADT7410 on I2C bus
CrossWorks Device Library CrossWorks Device Library
177
ADT7410_I2C_ADDR
Synopsis
#define ADT7410_I2C_ADDR(Ax) (0x90 + 2*(Ax))
CrossWorks Device Library CrossWorks Device Library
178
adt7410_initialize_i2c
Synopsis
CTL_STATUS_t adt7410_initialize_i2c(CTL_TEMPERATURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
adt7410_initialize_i2c initializes the temperature sensor interface self with methods to communicate with an
ADT7410 temperature sensor on the I2C bus bus with 8-bit I2C address addr.
Once the temperature sensor interface is initialized, you can use all standard temperature sensor methods from
the sensor API on the interface.
Return Value
adt7410_initialize_i2c returns a standard status code.
Thread Safety
adt7410_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
179
<bmp085.h>
Overview
Driver for a Bosch Sensortec BMP085 digital barometric pressure sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.bosch-sensortec.com/content/language1/html/3477.htm
Datasheet
http://www.bosch-sensortec.com/content/language1/downloads/BST-BMP085-DS000-05.pdf
Test hardware
This code has been tested using a SolderCore CorePressure module:
http://soldercore.com/products/sensecore/corepressure/
This was plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
BMP085_I2C_ADDR BMP085 8-bit I2C address
Types
BMP085_BAROMETER_t BMP085 sensor state
Functions
bmp085_initialize_i2c Initialize sensor on I2C bus
bmp085_set_resolution Set sensor resolution
CrossWorks Device Library CrossWorks Device Library
180
BMP085_BAROMETER_t
Synopsis
typedef struct { CTL_PRESSURE_SENSOR_t core;} BMP085_BAROMETER_t;
Description
BMP085_BAROMETER_t contains the internal calibration and resolution settings that should be considered
inaccessible by the client. The core pressure sensor member, core, is the only user-accessible member. You can
pass the address of core to the abstract pressure sensor API in ctl_sensors_h.
CrossWorks Device Library CrossWorks Device Library
181
BMP085_I2C_ADDR
Synopsis
#define BMP085_I2C_ADDR 0xEE
Description
BMP085_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
182
bmp085_initialize_i2c
Synopsis
CTL_STATUS_t bmp085_initialize_i2c(BMP085_BAROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
bmp085_initialize_i2c initializes the BMP085 pressure sensor self on I2C bus bus using the 8-bit I2C address
addr.
During initialization, bmp085_initialize_i2c tries to read calibration data from the sensor, with up to ten retries.
If the data can be read without error, bmp085_initialize_i2c returns CTL_NO_ERROR.
Once the pressure sensor interface is initialized, you can use all standard pressure sensor methods from the
sensor API on the interface.
Return Value
bmp085_initialize_i2c will return any error reported by the underlying I2C driver without retrying. If the sensor
data is unavailable after ten retries, bmp085_initialize_i2c returns CTL_READ_ERROR.
Thread Safety
bmp085_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
183
bmp085_set_resolution
Synopsis
CTL_STATUS_t bmp085_set_resolution(BMP085_BAROMETER_t *self, int bits);
bmp085_set_resolution sets the sensor self to use the sensitivity setting delivering bits of ADC data. bits can be
one of:
Bits Setting Conversion time (ms) Number of samples
16 Ultra-low power 4.5 1
17 Standard 7.5 2
18 High resolution 13.5 4
19 Ultra-high resolution 25.5 8
Return Value
bmp085_set_resolution returns a standard status code.
Thread Safety
bmp085_set_resolution is thread-safe if the transport member in self is thread-safe. This requires that a mutex
is associated with the I2C bus provided when initializing self.
CrossWorks Device Library CrossWorks Device Library
184
<dht.h>
Overview
Driver for MaxDetect Technology RHT range of sensors.
These sensors report measurements using two different formats, so clients are required to specify the attached
sensor type at initialization time.
The RHT01, RHT02, RHT03, DHT22, and AM2302 are all the same product.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.humiditycn.com/
Test hardware
This code has been tested using DHT11, DHT22, and RHT03 sensors acquired from SparkFun and AdaFruit.
The sensors were wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Functions
dht_read_humidity Read humidity
CrossWorks Device Library CrossWorks Device Library
185
dht_read_humidity
Synopsis
CTL_STATUS_t dht_read_humidity(DHT_DRIVER_t *self, float *t, float *rh);
Description
dht_read_humidity starts a measurement of humidity using DHT self.
dht_read_humidity returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
186
<hih6130.h>
Overview
Driver for a Honeywell HIH6130 humidity and temperature sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://sensing.honeywell.com/product%20page?pr_id=142038
Datasheet
http://sensing.honeywell.com/honeywell-sensing-humidicon-hih6130-6131-6120-6121-series-
productsheet.pdf
Test hardware
This code has been tested using a SparkFun HIH6130 breakout:
http://www.sparkfun.com/products/11295
This was plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
HIH6130_I2C_ADDR HIH6130 8-bit I2C address
Functions
hih6130_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
187
HIH6130_I2C_ADDR
Synopsis
#define HIH6130_I2C_ADDR 0x4E
Description
HIH6130_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
188
hih6130_initialize_i2c
Synopsis
CTL_STATUS_t hih6130_initialize_i2c(CTL_HUMIDITY_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
hih6130_initialize_i2c initializes the humidity sensor interface self with methods to communicate with an
HIH6130 humidity sensor on the I2C bus bus with 8-bit I2C address addr.
Once the humidity sensor interface is initialized, you can use all standard humidity sensor methods from the
sensor API on the interface.
Return Value
hih6130_initialize_i2c returns a standard status code.
Thread Safety
hih6130_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
189
<isl29023.h>
Overview
Driver for an Intersil ISL29023 ambient light sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.intersil.com/en/products/optoelectronics/ambient-light-sensors/light-to-digital-sensors/
ISL29023.html
Datasheet
Intersil require you to register and request a full datasheet.
Note
This implementation assumes a 499kOhm Rext resistor. See http://www.intersil.com/data/fn/fn6691.pdf
Test hardware
This code has been tested using a SolderCore CoreLight module:
http://soldercore.com/products/sensecore/corelight/
This was plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Range (lux) 1000, 4000, 16000, 64000 (default)
Resolution (bits) 4, 8, 12, 16 (default)
CrossWorks Device Library CrossWorks Device Library
190
Communication up to 400 kHz (I2C)
API Summary
Macros
ISL29023_I2C_ADDR ISL29023 8-bit I2C address
Types
ISL29023_DRIVER_t ISL29023 light sensor
Functions
isl29023_initialize_i2c Initialize sensor on I2C bus
isl29023_set_range Set sensor range
isl29023_set_resolution_bits Set sensor resolution
CrossWorks Device Library CrossWorks Device Library
191
ISL29023_DRIVER_t
Synopsis
typedef struct { CTL_LIGHT_SENSOR_t core; float __range; int __resolution;} ISL29023_DRIVER_t;
Description
ISL29023_DRIVER_t encapsulates the required data to interface an ISL29023 light sensor.
Structure
core
The core light sensor structure.
__range
Private member: the selected range of the sensor, in lux.
__resolution
Private member: the selected resolution of the sensor, in bits.
CrossWorks Device Library CrossWorks Device Library
192
ISL29023_I2C_ADDR
Synopsis
#define ISL29023_I2C_ADDR 0x88
Description
ISL29023_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
193
isl29023_initialize_i2c
Synopsis
CTL_STATUS_t isl29023_initialize_i2c(ISL29023_DRIVER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
isl29023_initialize_i2c initializes the light sensor interface self with methods to communicate with an ISL29023
ambient light sensor on the I2C bus bus with 8-bit I2C address addr.
Once the light sensor interface is initialized, you can use all standard light sensor methods from the sensor API
on the interface self->core.
Return Value
isl29023_initialize_i2c returns a standard status code.
Thread Safety
isl29023_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
194
isl29023_set_range
Synopsis
CTL_STATUS_t isl29023_set_range(ISL29023_DRIVER_t *self, float lux);
Sets the full scale range of the light sensor to at least lux lux.
Return Value
isl29023_set_range returns a standard status code.
Thread Safety
isl29023_set_range is thread-safe if a mutex is associated with the I2C bus the sensor is attached to.
CrossWorks Device Library CrossWorks Device Library
195
isl29023_set_resolution_bits
Synopsis
CTL_STATUS_t isl29023_set_resolution_bits(ISL29023_DRIVER_t *self, int bits);
Sets the resolution of the light sensor to at least bits bits. The valid resolutions for this sensor are 4, 8, 12, and 16
bits.
Return Value
isl29023_set_resolution_bits returns a standard status code.
Thread Safety
isl29023_set_resolution_bits is thread-safe if a mutex is associated with the I2C bus the sensor is attached to.
CrossWorks Device Library CrossWorks Device Library
196
<lm75.h>
Overview
Driver for LM75 temperature sensor.
National Semiconductor is now a wholly-owned subsidiary of Texas Instruments. Many temperature sensors are
compatible with the original LM75, and many of them offer higher resolution, accuracy and additional features.
This driver provides a standard view of the LM75 with fixed dynamic resolution.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.ti.com/product/lm75a
Datasheet
http://www.ti.com/lit/ds/symlink/lm75a.pdf
Test hardware
This code has been tested using the LM75 of a Gravitech 7-segment shield: http://
www.gravitech.us/7segmentshield.html
This was plugged into a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Resolution (°C) 0.5 (fixed)
Communication up to 400 kHz (I2C)
API Summary
Macros
LM75_I2C_ADDR LM75 8-bit I2C address
Functions
lm75_initialize_i2c Initialize LM75 on I2C bus
lm75_initialize_i2c_ex Initialize LM75-compatible on I2C bus
CrossWorks Device Library CrossWorks Device Library
197
LM75_I2C_ADDR
Synopsis
#define LM75_I2C_ADDR 0x90
Description
LM75_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
198
lm75_initialize_i2c
Synopsis
CTL_STATUS_t lm75_initialize_i2c(CTL_TEMPERATURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lm75_initialize_i2c initializes the temperature sensor interface self with methods to communicate with an LM75
temperature sensor on the I2C bus bus with 8-bit I2C address addr.
Once the temperature sensor interface is initialized, you can use all standard temperature sensor methods from
the sensor API on the interface.
Return Value
lm75_initialize_i2c returns a standard status code.
Thread Safety
lm75_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C transports,
you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
199
lm75_initialize_i2c_ex
Synopsis
CTL_STATUS_t lm75_initialize_i2c_ex(CTL_TEMPERATURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr, int bits);
Description
lm75_initialize_i2c_ex initializes the temperature sensor interface self with methods to communicate with an
LM75-compatible temperature sensor on the I2C bus bus with 8-bit I2C address addr and bits bits of resolution.
Once the temperature sensor interface is initialized, you can use all standard temperature sensor methods from
the sensor API on the interface.
Some compatibles, for instance the NXP LM75B, have extra resolution. The LM75B has 11 bits of resolution to
resolve 0.125°C. In this case, you would call lm75_initialize_i2c_ex with bits set to 11.
Return Value
lm75_initialize_i2c_ex returns a standard status code.
Thread Safety
lm75_initialize_i2c_ex is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
200
<lps331ap.h>
Overview
Driver for an STMicroelectronics LPS331AP digital barometric pressure sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/internet/analog/product/251601.jsp
Datasheet
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/
DM00036196.pdf
Test hardware
This code has been tested using an ST STEVAL-MKI120V1 module:
http://www.st.com/internet/evalboard/product/253479.jsp
API Summary
Macros
LPS331AP_I2C_ADDR LPS331AP 8-bit I2C address
Functions
lps331ap_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
201
LPS331AP_I2C_ADDR
Synopsis
#define LPS331AP_I2C_ADDR(SA0) (0xB8 + 2*(SA0))
Description
LPS331AP_I2C_ADDR returns the 8-bit I2C address for the LPS331AP selected by the state of signal SA0 which
can be low (0) or high (1).
CrossWorks Device Library CrossWorks Device Library
202
lps331ap_initialize_i2c
Synopsis
CTL_STATUS_t lps331ap_initialize_i2c(CTL_PRESSURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lps331ap_initialize_i2c initializes the pressure sensor interface self with methods to communicate with an
LPC331AP pressure sensor on I2C bus bus using the 8-bit I2C address addr.
Once the pressure sensor interface is initialized, you can use all standard pressure sensor methods from the
sensor API on the interface.
Return Value
lps331ap_initialize_i2c returns a standard status code.
Thread Safety
lps331ap_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
203
<ltr501als.h>
Overview
Driver for an LTR-501ALS ambient light sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://optoelectronics.liteon.com/en-global/Led/LED-Component/Detail/519
Datasheet
http://optoelectronics.liteon.com/upload/download/DS86-2012-0006/
P_100_LTR-501ALS-01_PrelimDS_ver1.1.pdf
Test hardware
This code has been tested using an Olimex MOD-LTR501-ALS:
http://www.olimex.com/Products/Modules/Sensors/MOD-LTR-501ALS
This is plugged into a custom CoreProto rivet and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Constants
LTR501ALS_I2C_ADDR LTR-501ALS I2C address
Functions
ltr501als_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
204
LTR501ALS_I2C_ADDR
Synopsis
#define LTR501ALS_I2C_ADDR 0x46
Description
LTR501ALS_I2C_ADDR is the 8-bit I2C address of the LTR-501ALS sensor.
CrossWorks Device Library CrossWorks Device Library
205
ltr501als_initialize_i2c
Synopsis
CTL_STATUS_t ltr501als_initialize_i2c(CTL_LIGHT_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
ltr501als_initialize_i2c initializes the LTR-501ALS ambient light sensor self on I2C bus bus using the 8-bit I2C
address addr.
During initialization, ltr501als_initialize_i2c attempts to communicate with the sensor to set the fastest
integration time with lowest gain.
Once the light sensor interface is initialized, you can use all standard light sensor methods from the sensor API
on the interface's core member.
Return Value
ltr501als_initialize_i2c returns a standard status code.
Thread Safety
ltr501als_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
206
<max6675.h>
Overview
Driver for Maxim MAX6675 K-type Thermocouple converter.
Note
If the MAX6675 detects that the thermocouple is open, the temperature is returned as NaN.
Test hardware
This code has been tested using a MOD-TC on an Olimexino-5510.
API Summary
Functions
max6675_initialize_spi Initialize sensor on SPI interface
CrossWorks Device Library CrossWorks Device Library
207
max6675_initialize_spi
Synopsis
CTL_STATUS_t max6675_initialize_spi(CTL_TEMPERATURE_SENSOR_t *self, CTL_SPI_DEVICE_t *dev);
CrossWorks Device Library CrossWorks Device Library
208
<mpl115a.h>
Overview
Driver for Freescale MPL115A1 and MPL115A2 pressure sensors.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL115A
Datasheet
MPL115A1 (PDF)
MPL115A2 (PDF)
Test hardware
This code has been tested using a SparkFun MPL115A1 breakout:
https://www.sparkfun.com/products/9721
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Notes
The polynomial used for pressure compensation is based on the Revision 6 LPC115A1 datasheet, published
10/2011:
• Pcomp = a0 + (b1 + c12 × Tadc) × Padc + b2 × Tadc
The Revision 4 MPL115A1 datasheet, published 03/2010, uses a slightly different method with additional
coefficients:
CrossWorks Device Library CrossWorks Device Library
209
• Pcomp = a0 + (b1 + c11×Padc + c12×Tadc) × Padc + (b2 + c22×Tadc) × Tadc
Freescale note that c11 and c22 were always set to zero in MPL115A devices and, therefore, the Revision 6
calculation is preferred (and equivalent in practice).
API Summary
Macros
MPL115A2_I2C_ADDRESS MPL115A2 8-bit I2C address
Initialization
mpl115a_initialize_i2c Initialize sensor on I2C bus
mpl115a_initialize_spi Initialize sensor on SPI interface
CrossWorks Device Library CrossWorks Device Library
210
MPL115A2_I2C_ADDRESS
Synopsis
#define MPL115A2_I2C_ADDRESS 0xC0
Description
MPL115A2_I2C_ADDRESS defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
211
mpl115a_initialize_i2c
Synopsis
CTL_STATUS_t mpl115a_initialize_i2c(MPL115A_BAROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
CrossWorks Device Library CrossWorks Device Library
212
mpl115a_initialize_spi
Synopsis
CTL_STATUS_t mpl115a_initialize_spi(MPL115A_BAROMETER_t *self, CTL_SPI_DEVICE_t *dev);
CrossWorks Device Library CrossWorks Device Library
213
<mpl3115a2.h>
Overview
Driver for Freescale MPL2115A2 pressure sensors.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPL3115A2
Datasheet
MPL3115A2 (PDF)
Test hardware
This code has been tested using an element-14/Freescale XTRINSIC-SENSORS-EVK:
http://uk.farnell.com/freescale-semiconductor/xtrinsic-sensors-evk/evaluation-kit-xtrinsic-sensor/
dp/2308734
This was wired to a CoreStack and installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
MPL3115A2_I2C_ADDRESS MPL3115A2 8-bit I2C address
Initialization
mpl3115a2_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
214
MPL3115A2_I2C_ADDRESS
Synopsis
#define MPL3115A2_I2C_ADDRESS 0xC0
Description
MPL3115A2_I2C_ADDRESS defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
215
mpl3115a2_initialize_i2c
Synopsis
CTL_STATUS_t mpl3115a2_initialize_i2c(CTL_PRESSURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
CrossWorks Device Library CrossWorks Device Library
216
<sht1x.h>
Overview
Driver for a Sensirion SHT1x humidity and temperature sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.sensirion.com/en/products/humidity-temperature/
Datasheet
http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity/
Sensirion_Humidity_SHT1x_Datasheet_V5.pdf
Test hardware
This code has been tested using a Parallax SHT11 breakout module:
Parallax SHT1x Sensor
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Constants
SHT1X_HIGH_RESOLUTION High resolution mode
SHT1X_LOW_RESOLUTION Low resolution mode
Initialization
sht1x_initialize Initialize SHT1x sensor
sht1x_set_resolution Select measurement resolution
sht1x_set_supply_voltage Set supply voltage for compensation
Measurement
sht1x_read_linear_humidity Read linear humidity
CrossWorks Device Library CrossWorks Device Library
217
sht1x_read_temperature Read supply-compensated temperature
sht1x_read_true_humidity Read temperature-compensated true humidity
Utility
sht1x_read_raw_humidity Read raw humidity ADC
sht1x_read_raw_temperature Read raw temperature ADC
sht1x_read_status Read sensor STATUS register
sht1x_soft_reset Soft-reset sensor
sht1x_write_status Write sensor STATUS register
CrossWorks Device Library CrossWorks Device Library
218
SHT1X_HIGH_RESOLUTION
Synopsis
#define SHT1X_HIGH_RESOLUTION 0
Description
SHT1X_HIGH_RESOLUTION can be passed as a parameter to sht1x_set_resolution to select SHT1x high
resolution mode.
See Also
sht1x_set_resolution
CrossWorks Device Library CrossWorks Device Library
219
SHT1X_LOW_RESOLUTION
Synopsis
#define SHT1X_LOW_RESOLUTION 1
Description
SHT1X_LOW_RESOLUTION can be passed as a parameter to sht1x_set_resolution to select SHT1x low
resolution mode.
See Also
sht1x_set_resolution
CrossWorks Device Library CrossWorks Device Library
220
sht1x_initialize
Synopsis
CTL_STATUS_t sht1x_initialize(SHT1X_DRIVER_t *self, int sample_delay);
Description
sht1x_initialize initializes the SHT1x to high-resolution mode and sets a default supply voltage of 3V.
sht1x_initialize automatically issues a soft reset to the SHT1x, and waits the required 11ms for the reset to
complete, before returning.
sht1x_initialize returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
221
sht1x_read_linear_humidity
Synopsis
CTL_STATUS_t sht1x_read_linear_humidity(SHT1X_DRIVER_t *self, float *measurement);
Description
sht1x_read_linear_humidity starts a measurement of linear humidity using SHT1x self and the set resolution.
The linear humidity is not compensated for temperature.
sht1x_read_linear_humidity returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
222
sht1x_read_raw_humidity
Synopsis
CTL_STATUS_t sht1x_read_raw_humidity(SHT1X_DRIVER_t *self);
Description
sht1x_read_raw_humidity starts a measurement of humidity using SHT1x self and the set resolution. On
completion, sht1x_read_raw_humidity returns the raw humidity ADC measurement as the function result.
sht1x_read_raw_humidity returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
223
sht1x_read_raw_temperature
Synopsis
CTL_STATUS_t sht1x_read_raw_temperature(SHT1X_DRIVER_t *self);
Description
sht1x_read_raw_temperature starts a measurement of temperature using SHT1x self and the set resolution.
On completion, sht1x_read_raw_temperature returns the raw temperature ADC measurement as the function
result.
sht1x_read_raw_temperature returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
224
sht1x_read_status
Synopsis
CTL_STATUS_t sht1x_read_status(SHT1X_DRIVER_t *self);
Description
sht1x_read_status reads the STATUS register of SHT1x self and returns it as the function result.
sht1x_read_status returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
225
sht1x_read_temperature
Synopsis
CTL_STATUS_t sht1x_read_temperature(SHT1X_DRIVER_t *self, float *measurement);
Description
sht1x_read_temperature starts a measurement of temperature using SHT1x self and the set resolution. On
completion, the raw temperature ADC is converted to degrees Celsius with compensation for the supply voltage.
The compensated temperature measurement is stored to measurement.
sht1x_read_temperature returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
226
sht1x_read_true_humidity
Synopsis
CTL_STATUS_t sht1x_read_true_humidity(SHT1X_DRIVER_t *self, float *temperature, float *rh_linear, float *rh_true);
Description
sht1x_read_true_humidity starts a measurement of temperature and humidity using SHT1x self and the set
resolution. On completion, the raw temperature ADC is converted to degrees Celsius with compensation for the
supply voltage. The compensated temperature measurement is then used to compensate the linear humidity
measurement for true humidity.
The supply-compensated temperature measurement is stored to temperature, the linear humidity
measurement is stored to rh_linear, and the temperature-compensated linear humidity is stored to rh_true.
sht1x_read_true_humidity returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
227
sht1x_set_resolution
Synopsis
CTL_STATUS_t sht1x_set_resolution(SHT1X_DRIVER_t *self, int resolution);
Description
sht1x_set_resolution sets the measurement resolution of SHT1x self to resolution. If resolution is zero, high
resolution mode is selected. If resolution is non-zero, low resolution mode is selected.
sht1x_set_resolution returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
228
sht1x_set_supply_voltage
Synopsis
void sht1x_set_supply_voltage(SHT1X_DRIVER_t *self, float supply);
Description
sht1x_set_supply_voltage sets the indicated supply voltage of SHT1x self to supply.
Note
For accurate supply-compensated temperatures, and hence temperature-compensated pressures, you must
indicate to this driver the voltage supplied to the SHT1x on the VDD rail.
CrossWorks Device Library CrossWorks Device Library
229
sht1x_soft_reset
Synopsis
void sht1x_soft_reset(SHT1X_DRIVER_t *self);
Description
sht1x_soft_reset performs a soft reset of the sensor self. According to the datasheet, this resets the interface
and clears the STATUS register to default values.
Description
sht1x_soft_reset then waits at least 11ms for the reset to complete before returning.
After soft reset, the driver is automatically set to high resolution mode.
CrossWorks Device Library CrossWorks Device Library
230
sht1x_write_status
Synopsis
CTL_STATUS_t sht1x_write_status(SHT1X_DRIVER_t *self, int value);
Description
sht1x_write_status write the STATUS register of SHT1x self with value and returns it as the function result.
sht1x_write_status returns any communication error in the function result.
CrossWorks Device Library CrossWorks Device Library
231
<sht2x.h>
Overview
Driver for a Sensirion SHT2x humidity and temperature sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.sensirion.com/en/products/humidity-temperature/humidity-sensor-sht21/
Datasheet
http://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/Humidity/
Sensirion_Humidity_SHT21_Datasheet_V3.pdf
Test hardware
This code has been tested using a Love Electronics SHT21 breakout module:
https://www.loveelectronics.co.uk/search?text=sht21
This was plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
SHT2x_I2C_ADDR SHT2x 8-bit I2C address
Types
SHT2x_RESOLUTION_t Sensor resolution encoding
Functions
sht2x_get_resolution Read resolution
sht2x_initialize_i2c Initialize sensor on I2C bus
sht2x_read_user Read user register
sht2x_set_resolution Set sensor resolution
CrossWorks Device Library CrossWorks Device Library
232
sht2x_write_user Write user register
CrossWorks Device Library CrossWorks Device Library
233
SHT2x_I2C_ADDR
Synopsis
#define SHT2x_I2C_ADDR 0x80
Description
SHT2x_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
234
SHT2x_RESOLUTION_t
Synopsis
typedef enum { SHT2x_12RH_14T, SHT2x_08RH_12T, SHT2x_10RH_13T, SHT2x_11RH_11T} SHT2x_RESOLUTION_t;
Description
SHT2x_RESOLUTION_t encodes the SHT2x sensor resolutions.
Resolutions
Name Description
SHT2x_12RH_14T Configure 12-bit relative humidity, 14-bit temperature.
SHT2x_08RH_12T Configure 8-bit relative humidity, 12-bit temperature.
SHT2x_10RH_13T Configure 10-bit relative humidity, 13-bit temperature.
SHT2x_11RH_11T Configure 11-bit relative humidity, 11-bit temperature.
CrossWorks Device Library CrossWorks Device Library
235
sht2x_get_resolution
Synopsis
CTL_STATUS_t sht2x_get_resolution(CTL_HUMIDITY_SENSOR_t *self);
Description
sht2x_get_resolution reads the configured resolution the sensor self.
Return Value
sht2x_get_resolution returns an extended status code: non-negative values indicate a successful read, and
value, of the resolution.
Thread Safety
sht2x_get_resolution is thread-safe if the transport member in self is thread-safe. This requires that a mutex is
associated with the I2C bus provided when calling sht2x_initialize_i2c.
CrossWorks Device Library CrossWorks Device Library
236
sht2x_initialize_i2c
Synopsis
CTL_STATUS_t sht2x_initialize_i2c(CTL_HUMIDITY_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
sht2x_initialize_i2c initializes the humidity sensor interface self with methods to communicate with an SHT2x
humidity sensor on the I2C bus bus with 8-bit I2C address addr.
Once the humidity sensor interface is initialized, you can use all standard humidity sensor methods from the
sensor API on the interface.
Return Value
sht2x_initialize_i2c returns a standard status code.
Thread Safety
sht2x_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
237
sht2x_read_user
Synopsis
CTL_STATUS_t sht2x_read_user(CTL_HUMIDITY_SENSOR_t *self);
Description
sht2x_read_user reads the user register of the sensor self.
Return Value
sht2x_read_user returns an extended status code: non-negative values indicate a successful read, and value, of
the user register.
Thread Safety
sht2x_read_user is thread-safe if the transport member in self is thread-safe. This requires that a mutex is
associated with the I2C bus provided when calling sht2x_initialize_i2c.
CrossWorks Device Library CrossWorks Device Library
238
sht2x_set_resolution
Synopsis
CTL_STATUS_t sht2x_set_resolution(CTL_HUMIDITY_SENSOR_t *self, SHT2x_RESOLUTION_t r);
Description
sht2x_set_resolution sets the sensor self to the resolution r.
Return Value
sht2x_set_resolution returns a standard status code.
Thread Safety
sht2x_set_resolution is thread-safe if the transport member in self is thread-safe. This requires that a mutex is
associated with the I2C bus provided when calling sht2x_initialize_i2c.
CrossWorks Device Library CrossWorks Device Library
239
sht2x_write_user
Synopsis
CTL_STATUS_t sht2x_write_user(CTL_HUMIDITY_SENSOR_t *self, int value);
Description
sht2x_write_user write the user register of the sensor self to value.
Return Value
sht2x_write_user returns a standard status code.
Thread Safety
sht2x_write_user is thread-safe if the transport member in self is thread-safe. This requires that a mutex is
associated with the I2C bus provided when calling sht2x_initialize_i2c.
CrossWorks Device Library CrossWorks Device Library
240
<si7005.h>
Overview
Driver for a Silicon Labs Si7005 humidity and temperature sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.silabs.com/products/sensors/humidity-sensors/Pages/si7005.aspx
Datasheet
http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7005.pdf
Test hardware
This code has been tested using a Silicon Labs Si7005EVB-UDP:
http://www.silabs.com/products/mcu/udp/Pages/si7005evb-udp.aspx
This was hand-wired to a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
SI7005_I2C_ADDR Si7005 8-bit I2C address
Functions
si7005_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
241
SI7005_I2C_ADDR
Synopsis
#define SI7005_I2C_ADDR 0x80
Description
SI7005_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
242
si7005_initialize_i2c
Synopsis
CTL_STATUS_t si7005_initialize_i2c(CTL_HUMIDITY_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
si7005_initialize_i2c initializes the humidity sensor interface self with methods to communicate with an Si7005
humidity sensor on the I2C bus bus with 8-bit I2C address addr.
Once the humidity sensor interface is initialized, you can use all standard humidity sensor methods from the
sensor API on the interface.
Return Value
si7005_initialize_i2c returns a standard status code.
Thread Safety
si7005_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
243
<tmp100.h>
Overview
Driver for TMP100 (and compatible) temperature sensors.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.ti.com/product/tmp100
Datasheet
http://www.ti.com/lit/ds/symlink/tmp100.pdf
Specification
Parameter Supported settings
Resolution (°C) 0.5 (default), 0.25, 0.125, 0.00625
Communication up to 3.4 MHz (I2C)
API Summary
Macros
TMP100_I2C_ADDR TMP100 8-bit I2C address
Functions
tmp100_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
244
TMP100_I2C_ADDR
Synopsis
#define TMP100_I2C_ADDR 0x90
Description
TMP100_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
245
tmp100_initialize_i2c
Synopsis
CTL_STATUS_t tmp100_initialize_i2c(CTL_TEMPERATURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
tmp100_initialize_i2c initializes the temperature sensor interface self with methods to communicate with a
TMP100 temperature sensor on the I2C bus bus with 8-bit I2C address addr.
Once the temperature sensor interface is initialized, you can use all standard temperature sensor methods from
the sensor API on the interface.
tmp100_initialize_i2c returns a standard status code.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
246
<tmp102.h>
Overview
Driver for TMP102 (and compatible) temperature sensors.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.ti.com/product/tmp102
Datasheet
http://www.ti.com/lit/ds/symlink/tmp102.pdf
Test hardware
This code has been tested using a SparkFun TMP102 breakout board:
http://www.sparkfun.com/products/9418
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Resolution (°C) 0.0625 (fixed)
Range (°C) −55 to +128 (default), −55 to +150 (extended mode).
Communication up to 3.4 MHz (I2C)
API SummaryMacros
TMP102_I2C_ADDR TMP102 8-bit I2C address
TMP275_I2C_ADDR TMP275 8-bit I2C address
Functions
tmp102_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
247
tmp102_set_extended_mode Select extended temperature range
CrossWorks Device Library CrossWorks Device Library
248
TMP102_I2C_ADDR
Synopsis
#define TMP102_I2C_ADDR 0x90
Description
TMP102_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
249
TMP275_I2C_ADDR
Synopsis
#define TMP275_I2C_ADDR(ADx) (0x90 + 2*(ADx))
Description
TMP275_I2C_ADDR defines the default 8-bit I2C address for the TMP275 according to the ADx inputs as
specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
250
tmp102_initialize_i2c
Synopsis
CTL_STATUS_t tmp102_initialize_i2c(CTL_TEMPERATURE_SENSOR_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
tmp102_initialize_i2c initializes the temperature sensor interface self with methods to communicate with a
TMP102 temperature sensor on the I2C bus bus with 8-bit I2C address addr.
Once the temperature sensor interface is initialized, you can use all standard temperature sensor methods from
the sensor API on the interface.
tmp102_initialize_i2c returns a standard status code.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
251
tmp102_set_extended_mode
Synopsis
CTL_STATUS_t tmp102_set_extended_mode(CTL_TEMPERATURE_SENSOR_t *self, int enable);
Description
tmp102_set_extended_mode enables or disables the TMP102's Extended Mode for 13-bit temperature data.
In extended mode, the resolution stays the same as normal mode at 0.5°C but the upper limit is extended to
+150°C.
tmp102_set_extended_mode returns a standard status code.
CrossWorks Device Library CrossWorks Device Library
252
<tsl2561.h>
Overview
Driver for an AMS TSL2561 ambient light sensor.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.ams.com/eng/Products/Light-Sensors/Ambient-Light-Sensor-ALS/TSL2561
Datasheet
http://www.ams.com/eng/content/download/250093/975477/142937
Test hardware
This code has been tested using a JeeLabs Lux Plug:
http://jeelabs.com/products/lux-plug
This was installed on a JeeLabs Plug Shield:
http://jeelabs.com/products/plug-shield
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Constants
TSL2561_I2C_ADDR_FLOAT TSL2561 8-bit I2C address for ADDRSEL floating
TSL2561_I2C_ADDR_GND TSL2561 8-bit I2C address for ADDRSEL grounded
TSL2561_I2C_ADDR_VDD TSL2561 8-bit I2C address for ADDRSEL tied to Vdd
Types
TSL2561_DRIVER_t TSL2561 light sensor
Functions
tsl2561_initialize_i2c Initialize sensor on I2C bus
tsl2561_set_integration_time Set sensor integration time
CrossWorks Device Library CrossWorks Device Library
253
TSL2561_DRIVER_t
Synopsis
typedef struct { CTL_LIGHT_SENSOR_t core; unsigned __id;} TSL2561_DRIVER_t;
Description
TSL2561_DRIVER_t encapsulates the required data to interface a TSL2561 light sensor.
Structure
core
The core light sensor structure.
__id
Private member: the device ID of the specific light sensor detected during initialization.
CrossWorks Device Library CrossWorks Device Library
254
TSL2561_I2C_ADDR_FLOAT
Synopsis
#define TSL2561_I2C_ADDR_FLOAT 0x72
Description
TSL2561_I2C_ADDR_FLOAT is the 8-bit I2C address of the TSL2561 sensor with ADDRSEL left floating.
CrossWorks Device Library CrossWorks Device Library
255
TSL2561_I2C_ADDR_GND
Synopsis
#define TSL2561_I2C_ADDR_GND 0x52
Description
TSL2561_I2C_ADDR_GND is the 8-bit I2C address of the TSL2561 sensor with ADDRSEL tied to ground.
CrossWorks Device Library CrossWorks Device Library
256
TSL2561_I2C_ADDR_VDD
Synopsis
#define TSL2561_I2C_ADDR_VDD 0x92
Description
TSL2561_I2C_ADDR_VDD is the 8-bit I2C address of the TSL2561 sensor with ADDRSEL tied to Vdd.
CrossWorks Device Library CrossWorks Device Library
257
tsl2561_initialize_i2c
Synopsis
CTL_STATUS_t tsl2561_initialize_i2c(TSL2561_DRIVER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
tsl2561_initialize_i2c initializes the TS2561 ambient light sensor self on I2C bus bus using the 8-bit I2C address
addr.
During initialization, tsl2561_initialize_i2c attempts to communicate with the sensor to set the fastest
integration time with lowest gain.
Once the light sensor interface is initialized, you can use all standard light sensor methods from the sensor API
on the interface's core member.
Return Value
tsl2561_initialize_i2c returns a standard status code.
Thread Safety
tsl2561_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
258
tsl2561_set_integration_time
Synopsis
CTL_STATUS_t tsl2561_set_integration_time(TSL2561_DRIVER_t *self, int time);
Description
tsl2561_set_integration_time sets the integration time for the TSL2561 self to time.
When time is zero, the integration time is 13.7ms, when time is one, the integration time is 101ms, and when
time is 2 the integration time is 402ms.
Return Value
tsl2561_set_integration_time returns a standard status code.
Thread Safety
tsl2561_set_integration_time is thread-safe if a mutex is associated with the I2C bus the sensor is attached to.
CrossWorks Device Library CrossWorks Device Library
259
<ads7846.h>
API Summary
Functions
ads7846_init Initialize
CrossWorks Device Library CrossWorks Device Library
260
ads7846_init
Synopsis
CTL_STATUS_t ads7846_init(ADS7846_DRIVER_t *self, CTL_SPI_DEVICE_t *spi, int clock);
CrossWorks Device Library CrossWorks Device Library
261
<hd44780.h>
Overview
Driver for an Hitachi HD4470 display.
Compatible driver chips are the Samsung KS0066 and the Seiko-Epson SED1278.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Datasheet
http://lcd-linux.sourceforge.net/pdfdocs/hd44780.pdf
API SummaryConstants
HD44780_4BIT_INTERFACE 4-bit or 8-bit physical interface flag
HD44780_BIDIRECTIONAL_DBUS Unidirectional or bidirectional bus physical interfaceflag
ANSI parser
HD44780_ANSI_DRIVER_t ANSI control parser for HD44780 displays
hd44780_ansi_init Initialize LCD ANSI control sequence parser
Types
HD44780_DRIVER_t Virtual method table for display driver
Output functions
hd44780_putc Write character to LCD
hd44780_puts Write zero-terminated string to LCD
hd44780_set_cursor_position Set cursor position
hd44780_write Write fixed-length string to LCD
Control functions
hd44780_clear Clear display
hd44780_cursor_off Turn cursor off
hd44780_cursor_on Turn cursor on
hd44780_display_off Turn display off
hd44780_display_on Turn display on
hd44780_set_backlight Set LCD backlight level
CrossWorks Device Library CrossWorks Device Library
262
Low-level functions
hd44780_reset Reset the LCD
hd44780_send_cmd Issue low-level LCD command
CrossWorks Device Library CrossWorks Device Library
263
HD44780_4BIT_INTERFACE
Synopsis
#define HD44780_4BIT_INTERFACE (1<<1)
Description
Setting HD44780_4BIT_INTERFACE as a capability flag returned by the capabilities method indicates that the
data bus is interfaced with four bits (DB4 through DB7) and that the high-level driver should use four-bit mode. If
this flag is clear, the high-level driver runs the physical interface in 8-bit mode which is faster than 4-bit mode.
CrossWorks Device Library CrossWorks Device Library
264
HD44780_ANSI_DRIVER_t
Synopsis
typedef struct { ANSI_PARSER_t parser; HD44780_DRIVER_t *driver;} HD44780_ANSI_DRIVER_t;
Description
Definition of ANSI control sequence parser for HD4470-based displays.
CrossWorks Device Library CrossWorks Device Library
265
HD44780_BIDIRECTIONAL_DBUS
Synopsis
#define HD44780_BIDIRECTIONAL_DBUS (1<<0)
Description
Setting HD44780_BIDIRECTIONAL_DBUS as a capability flag returned by the capabilities method indicates
that the data bus direction can be controlled and the data bus can operate in both input and output mode.
LCD display will be much faster if the LCD is operated in bidirectional mode because the ‘LCD ready’ status can
be read from the bus to indicate that the LCD is ready; for output-only (unidirectional) interfaces, this status
cannot be read from the data bus so the high-level driver falls back to the minimum timings for each HD44780
command that are given in the datasheet.
CrossWorks Device Library CrossWorks Device Library
266
HD44780_DRIVER_t
Synopsis
typedef struct { int (*capabilities)(HD44780_DRIVER_t *); void (*set_e)(HD44780_DRIVER_t *, int); void (*set_rw)(HD44780_DRIVER_t *, int); void (*set_rs)(HD44780_DRIVER_t *, int); void (*set_dbus)(HD44780_DRIVER_t *, int); void (*set_backlight)(HD44780_DRIVER_t *, int); int (*read_dbus)(HD44780_DRIVER_t *); void *extra; int x; int y; int cursor; int width; int height; char lcd[];} HD44780_DRIVER_t;
Description
HD44780_DRIVER_t contains a set of methods that the high-level driver uses to implement the physical layer of
the display.
Structure
capabilities
Returns the underlying capabilities of the physical interface. The method should return the bitwise-or of
the flags HD44780_BIDIRECTIONAL_DBUS and HD44780_4BIT_INTERFACE. If the data bus is bidirectional
then the high-level driver will try to read the bus using read_dbus (to establish LCD readiness) and set its
control its direction using set_dbus_input and set_dbus_output. Returning HD44780_4BIT_INTERFACE
indicates that the data bus bus is physically connected using only four bits and the physical-layer driver
adapts to 4-bit mode.
set_e
Sets the E signal high when state is non-zero and low when state is zero.
set_rw
Sets the R/W signal high when state is non-zero and low when state is zero.
set_rs
Sets the RS signal high when state is non-zero and low when state is zero.
set_dbus
Sets the data bus to output mode and its outputs to state. For a 4-bit data bus, state will contain valid data
in bits 4 through 7 with all other bits zero, and for an 8-bit data bus, state will contain valid data in bits 0
through 7.
CrossWorks Device Library CrossWorks Device Library
267
set_backlight
Sets the display backlight level to level. This is a driver-specific function that is provided as a convenience in
order to enable clients to turn the backlight on and off, or to set its level using PWM.
read_dbus
Sets the data bus to input mode, reads the data bus, and returns what is read. For a 4-bit data bus, the four
data bits are expected in bits 4 through 7 and for an 8-bit data bus they are expected in bits 0 through 7.
CrossWorks Device Library CrossWorks Device Library
268
hd44780_ansi_init
Synopsis
void hd44780_ansi_init(HD44780_ANSI_DRIVER_t *self, HD44780_DRIVER_t *driver);
Description
hd44780_ansi_init initializes the ANSI parser self such that display output is driven to the LCD driver driver.
CrossWorks Device Library CrossWorks Device Library
269
hd44780_clear
Synopsis
void hd44780_clear(HD44780_DRIVER_t *self);
Description
hd44780_clear clears the display self and moves the cursor to the top-left position (0, 0). None of the user-
defined characters are altered and nor is the cursor display mode changed.
CrossWorks Device Library CrossWorks Device Library
270
hd44780_cursor_off
Synopsis
void hd44780_cursor_off(HD44780_DRIVER_t *self);
Description
hd44780_cursor_off turns the blinking cursor of display self off.
CrossWorks Device Library CrossWorks Device Library
271
hd44780_cursor_on
Synopsis
void hd44780_cursor_on(HD44780_DRIVER_t *self);
Description
hd44780_cursor_on turns the blinking cursor of display self off.
CrossWorks Device Library CrossWorks Device Library
272
hd44780_display_off
Synopsis
void hd44780_display_off(HD44780_DRIVER_t *self);
Description
hd44780_display_off turns off the LCD display such that it is blank; you can still write to the display, but the
display will not show any changes whilst off. Turning off a display that is already off has no effect.
You can turn the display back on using hd44780_display_on.
CrossWorks Device Library CrossWorks Device Library
273
hd44780_display_on
Synopsis
void hd44780_display_on(HD44780_DRIVER_t *self);
Description
hd44780_display_on turns on the LCD display such that it shows its previous contents. Turning on a display
that is already on has no effect.
CrossWorks Device Library CrossWorks Device Library
274
hd44780_putc
Synopsis
void hd44780_putc(HD44780_DRIVER_t *self, int u);
Description
hd44780_putc writes the 8-bit character u to the display self. The character is written directly without
interpreting it as a control code and, hence, all characters of the LCD character generator ROM and all user-
definable characters can be written to the display.
CrossWorks Device Library CrossWorks Device Library
275
hd44780_puts
Synopsis
void hd44780_puts(HD44780_DRIVER_t *self, const char *s);
Description
hd44780_puts writes the null-terminated string pointed to by s to the display self. Each character in s, excluding
the terminating null character, is written to the display using hd44780_putc.
CrossWorks Device Library CrossWorks Device Library
276
hd44780_reset
Synopsis
void hd44780_reset(HD44780_DRIVER_t *self);
Description
hd44780_reset resets the LCD, clears the screen, and readies the display.
CrossWorks Device Library CrossWorks Device Library
277
hd44780_send_cmd
Synopsis
void hd44780_send_cmd(HD44780_DRIVER_t *self, unsigned char cmd);
Description
hd44780_send_cmd sends the command cmd to the display self.
CrossWorks Device Library CrossWorks Device Library
278
hd44780_set_backlight
Synopsis
void hd44780_set_backlight(HD44780_DRIVER_t *self, int level);
Description
hd44780_set_backlight sets the backlight level of the display self to level. Whilst there is no LCD command to
implement this, a driver may wish to implement the set_backlight method of the interface so that the display
backlight is controllable using hd44780_set_backlight.
CrossWorks Device Library CrossWorks Device Library
279
hd44780_set_cursor_position
Synopsis
void hd44780_set_cursor_position(HD44780_DRIVER_t *self, int x, int y);
Description
hd44780_set_cursor_position moves the cursor on the LCD self to the position (x, y). Position (0, 0) is defined as
the top-left corner of the display.
CrossWorks Device Library CrossWorks Device Library
280
hd44780_write
Synopsis
void hd44780_write(HD44780_DRIVER_t *self, const char *s, size_t len);
Description
hd44780_write writes the fixed-length string pointed to by s to the display self. len characters are written to
the display using hd44780_putc.
CrossWorks Device Library CrossWorks Device Library
281
<mpr121.h>
Overview
Driver for a Freescale MPR121 capacitive touch controller.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MPR121
API Summary
Macros
MPR121_ADDRESS_SCL Default I2C address with ADDR connected to SCL
MPR121_ADDRESS_SDA Default I2C address with ADDR connected to SDA
MPR121_ADDRESS_VDD Default I2C address with ADDR connected to VDD
MPR121_ADDRESS_VSS Default I2C address with ADDR connected to VSS
CrossWorks Device Library CrossWorks Device Library
282
MPR121_ADDRESS_SCL
Synopsis
#define MPR121_ADDRESS_SCL 0xBA
Description
MPR121_ADDRESS_SCL defines the default 8-bit I2C address for the MPR121 when ADDR is connected to SCL.
CrossWorks Device Library CrossWorks Device Library
283
MPR121_ADDRESS_SDA
Synopsis
#define MPR121_ADDRESS_SDA 0xB8
Description
MPR121_ADDRESS_SDA defines the default 8-bit I2C address for the MPR121 when ADDR is connected to SDA.
CrossWorks Device Library CrossWorks Device Library
284
MPR121_ADDRESS_VDD
Synopsis
#define MPR121_ADDRESS_VDD 0xB4
Description
MPR121_ADDRESS_VDD defines the default 8-bit I2C address for the MPR121 when ADDR is connected to VDD.
CrossWorks Device Library CrossWorks Device Library
285
MPR121_ADDRESS_VSS
Synopsis
#define MPR121_ADDRESS_VSS 0xB6
Description
MPR121_ADDRESS_VSS defines the default 8-bit I2C address for the MPR121 when ADDR is connected to VSS.
CrossWorks Device Library CrossWorks Device Library
286
<wii_controller.h>
Overview
Driver for a Nintendo Wii extension controllers.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Protocol information
The Nunchuk protocol information is found here:
http://wiibrew.org/wiki/Classic_Controller#Data_Format_.28Nunchuk.29
The Classic Controller protocol information is found here:
http://wiibrew.org/wiki/Classic_Controller#Data_Format_.28Classic_Controller.29
Additional information available here:
http://wiibrew.org/wiki/Wiimote
http://wiire.org/Talk:Wii/protocols/wiimote_bus
Test hardware
This software was tested on a SolderCore with a SenseCore and Nunchuk adapter:
http://www.soldercore.com/
It was also tested using a Protoshield and WiiChuck adapter from Sparkfun:
http://www.sparkfun.com/commerce/product_info.php?products_id=9281
API Summary
Classic
WII_CLASSIC_REPORT_t Classic controller status report structure
wii_classic_sample Sample joystick, button, and trigger state
Nunchuk
WII_NUNCHUK_REPORT_t Nunchuk controller status report structure
wii_nunchuk_accelerometer_interface Create abstract accelerometer interface
wii_nunchuk_sample Sample accelerometer, joystick, and button state
Initialization
CrossWorks Device Library CrossWorks Device Library
287
wii_extension_controller_initialize Initialize extension controller
Controller
wii_extension_controller_read_memory Read extension controller memory
wii_extension_controller_write_memory_byte Write extension controller memory
CrossWorks Device Library CrossWorks Device Library
288
WII_CLASSIC_REPORT_t
Synopsis
typedef struct { int left_joystick_y; int right_joystick_y; int right_trigger_pressure; unsigned buttons_pressed;} WII_CLASSIC_REPORT_t;
Description
WII_CLASSIC_REPORT_t contains the data returned in a Wii Classic controller report.
CrossWorks Device Library CrossWorks Device Library
289
WII_NUNCHUK_REPORT_t
Synopsis
typedef struct { int accel_z; int accel_y; int joystick_y; int z_pressed; int c_pressed;} WII_NUNCHUK_REPORT_t;
Description
WII_NUNCHUK_REPORT_t contains the data returned in a Wii Nunchuk controller report.
CrossWorks Device Library CrossWorks Device Library
290
wii_classic_sample
Synopsis
CTL_STATUS_t wii_classic_sample(CTL_I2C_BUS_t *bus, WII_CLASSIC_REPORT_t *report);
Description
wii_classic_sample samples the joysticks, triggers, and the buttons on the Classic Controller attached to bus bus
and writes the result to the structure pointed to by report. All data are returned as raw values directly from the
received report.
Return Value
wii_classic_sample returns a standard status code. If the status indicates an error, the returned sample data is
undefined.
Thread Safety
wii_classic_sample is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
291
wii_extension_controller_initialize
Synopsis
CTL_STATUS_t wii_extension_controller_initialize(CTL_I2C_BUS_t *bus);
Description
wii_extension_controller_initialize initializes the extension controller on the I2C bus bus. The I2C driver must
already have been initialized and the I2C clock frequency set.
Note
Experimentation reveals that the nunchuk will run from 100 kHz to about 300kHz, and not at the upper 400 kHz
of high-speed I2C. This may be because of non-shielded prototyping wires used during driver development, so
you may well have to experiment with a slower clock frequency; 275kHz works well.
Return Value
wii_extension_controller_initialize returns a standard status code.
Thread Safety
wii_extension_controller_initialize is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
292
wii_extension_controller_read_memory
Synopsis
CTL_STATUS_t wii_extension_controller_read_memory(CTL_I2C_BUS_t *bus, int mem_addr, void *data, int n);
Description
wii_extension_controller_read_memory reads the contents of a Wii extension controller on I2C bus bus. n
bytes of memory are read from the controller starting at address mem_addr and written to the object pointed to
by data.
Return Value
wii_extension_controller_read_memory returns a standard status code.
Thread Safety
wii_extension_controller_read_memory is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
293
wii_extension_controller_write_memory_byte
Synopsis
CTL_STATUS_t wii_extension_controller_write_memory_byte(CTL_I2C_BUS_t *bus, int mem_addr, int value);
Description
wii_extension_controller_write_memory_byte writes value to the address mem_addr in the Wii extension
controller on I2C bus bus.
Return Value
wii_extension_controller_write_memory_byte returns a standard status code.
Thread Safety
wii_extension_controller_write_memory_byte is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
294
wii_nunchuk_accelerometer_interface
Synopsis
void wii_nunchuk_accelerometer_interface(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus);
Description
wii_nunchuk_accelerometer_interface initializes the abstract accelerometer interface self to sample
the nunchuk's accelerometer when requested. Once created, you can read the accelerometer using
ctl_accelerometer_measure on the interface bus.
Return Value
wii_nunchuk_accelerometer_interface returns a standard status code.
Thread Safety
wii_nunchuk_accelerometer_interface is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
295
wii_nunchuk_sample
Synopsis
CTL_STATUS_t wii_nunchuk_sample(CTL_I2C_BUS_t *bus, WII_NUNCHUK_REPORT_t *report);
Description
wii_nunchuk_sample samples the 3-axis accelerometer, 2-axis analog joystick, and the two buttons on the
nunchuk controller. All data are returned as raw values directly from the received report. Accelerometer readings
are 10 bits, 0 through 3FF; joystick readings are eight bits, 0 through FF, and button states are non-zero if the
corresponding button is pressed.
Return Value
wii_nunchuk_sample returns a standard status code. If the status indicates an error, the returned sample data is
undefined.
Thread Safety
wii_nunchuk_sample is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
296
<ak8975.h>
Overview
Driver for an Asahi Kasei AK8975 electronic compass.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.asahi-kasei.co.jp/akm/en/product/ak8975b/ak8975b.html
Datasheet
http://nexp.tistory.com/attachment/[email protected]
Test hardware
This code has been tested using an InvenSense MPU-6050 evaluation board with the MPU-6050 in bypass mode
to attach the auxiliary I2C bus to the primary I2C bus.
http://invensense.com/mems/gyro/documents/AN-MPU-6000EVB-00_v1.0.pdf
The MPU-6050 evaluation board was attached to a SolderCore:
http://www.soldercore.com/
Notes
Although the AK8975 supports SPI mode, we have no way to test this and consequently do not offer an SPI
initialization function.
Specification
Parameter Supported settings
Range (µT) ±1300
Communication up to 400 kHz (I2C) and 3 MHz (SPI)
API SummaryMacros
AK8975_I2C_ADDR AK8975 8-bit I2C address selected by CAD1:0
Functions
ak8975_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
297
ak8975_initialize_transport Initialize sensor on a transport
CrossWorks Device Library CrossWorks Device Library
298
AK8975_I2C_ADDR
Synopsis
#define AK8975_I2C_ADDR(CADx) (0x18 + 2*(CADx))
CrossWorks Device Library CrossWorks Device Library
299
ak8975_initialize_i2c
Synopsis
CTL_STATUS_t ak8975_initialize_i2c(CTL_MAGNETOMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
ak8975_initialize_i2c initializes the magnetometer interface self with methods to communicate with an AK8975
magnetometer on the I2C bus bus with 8-bit I2C address addr.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
ak8975_initialize_i2c returns a standard status code.
Thread Safety
ak8975_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
300
ak8975_initialize_transport
Synopsis
CTL_STATUS_t ak8975_initialize_transport(CTL_MAGNETOMETER_t *self, CTL_TRANSPORT_t *transport);
Description
ak8975_initialize_transport initializes the magnetometer interface self with an AK8975 magnetometer driver
using the transport transport to transfer I2C data. The transport transport must already have been initialized
with the I2C address of the target AK8975.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
ak8975_initialize_transport returns a standard status code.
Thread Safety
ak8975_initialize_transport is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
301
<bmm150.h>
Overview
Driver for Bosch Sensortec BMM150 3-axis magnetomoeter.
Resources
Web page
http://www.bosch-sensortec.com/homepage/products_3/3_axis_sensors/geomagnetic_sensors_3/
bmm150/bmm150
Datasheet
http://ae-bst.resource.bosch.com/media/products/dokumente/bmm150/BST-BMM150-DS001-01.pdf
Test hardware
This code has been tested using a BMC050-SHUTL module wire-wrapped on a prototyping shield and installed
on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
BMM150_I2C_ADDR BMM150 8-bit I2C address
Functions
bmm150_initialize_i2c Initialize sensor on I2C bus
bmm150_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
302
BMM150_I2C_ADDR
Synopsis
#define BMM150_I2C_ADDR(SEL) (0x20 + 2*(SEL))
Description
BMM150_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet for the
selection pins CSB:SDO pulled low or high. The standard 8-bit addresses are 0x20, 0x22, 0x24, and 0x26.
CrossWorks Device Library CrossWorks Device Library
303
bmm150_initialize_i2c
Synopsis
CTL_STATUS_t bmm150_initialize_i2c(CTL_MAGNETOMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
bmm150_initialize_i2c initializes the magnetometer interface self with methods to communicate with a
BMM150 magnetometer on the I2C bus bus with 8-bit I2C address addr.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
bmm150_initialize_i2c returns a standard status code.
Thread Safety
bmm150_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
304
bmm150_initialize_spi
Synopsis
CTL_STATUS_t bmm150_initialize_spi(CTL_MAGNETOMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
bmm150_initialize_spi initializes the magnetometer interface self with methods to communicate with an
BMM150 magnetometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI
mode 0. The maximum clock speed supported by the BMM150 in SPI mode is 10 MHz: you can increase the clock
speed from the initial 1 MHz using ctl_spi_set_speed.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
bmm150_initialize_spi returns a standard status code.
Thread Safety
bmm150_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
305
<fxos8700cq.h>
Overview
Driver for a Freescale FXOS8700CQ accelerometer + magnetometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FXOS8700CQ
Datasheet
http://cache.freescale.com/files/sensors/doc/data_sheet/FXOS8700CQ.pdf
Test hardware
This code has been tested using a FRDM-KL26Z:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=FRDM-KL26Z
Accelerometer Specification
Parameter Supported settings
Bandwidth (Hz) 0.78125, 3.125, 6.25, 25, 50, 100, 200, 500
Range (g) ±2, ±4, ±8
Communication up to 400 kHz (I2C)
API Summary
Macros
FXOS8700CQ_I2C_ADDR FXOS8700CQ 8-bit I2C address
Types
FXOS8700CQ_t Sensor group
Functions
fxos8700cq_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
306
FXOS8700CQ_I2C_ADDR
Synopsis
#define FXOS8700CQ_I2C_ADDR(SA) ((SA) == 0 ? 0x3C : \ (SA) == 1 ? 0x3A : \ (SA) == 2 ? 0x38 : \ 0x3E)
Description
FXOS8700CQ_I2C_ADDR defines the FXOS8700CQ 8-bit I2C address selected by the SA1:SA0 signals. From the
datasheet, the SA1:SA0 encoding is unexpected...
CrossWorks Device Library CrossWorks Device Library
307
FXOS8700CQ_t
Synopsis
typedef struct { CTL_IMU_t core; CTL_MAGNETOMETER_t mag; CTL_ACCELEROMETER_t accel;} FXOS8700CQ_t;
Description
FXOS8700CQ_t contains the instance data for the FXOS8700CQ accelerometer and magnetometer sensor
group.
Structure
core
The core IMU structure. The IMU structure is initialized with pointers to the accel and mag members, with
the gyro member set to zero.
accel
The instance containing the state of the FXOS8700CQ accelerometer.
mag
The instance containing the state of the FXOS8700CQ magnetometer.
CrossWorks Device Library CrossWorks Device Library
308
fxos8700cq_initialize_i2c
Synopsis
CTL_STATUS_t fxos8700cq_initialize_i2c(FXOS8700CQ_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
fxos8700cq_initialize_i2c initializes the FXOS8700CQ's accelerometer and magnetometer on the I2C bus
bus using the 8-bit I2C address addr. When complete, the the IMU member core is initialized pointing to the
appropriate members within self with the gyroscope set to zero.
Return Value
fxos8700cq_initialize_i2c returns a standard status code.
Thread Safety
fxos8700cq_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
309
<hmc5843.h>
Overview
Driver for a Honeywell HMC5843 magnetometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.magneticsensors.com/
Datasheet
http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/
Defense_Brochures-documents/HMC5843.pdf
Test hardware
This code has been tested using a SparkFun HMC5843 breakout: http://www.sparkfun.com/products/9371
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 116
Range (µT) ±400
Communication up to 400 kHz (I2C)
API Summary
Macros
HMC5843_I2C_ADDR HMC5843 8-bit I2C address
Functions
hmc5843_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
310
HMC5843_I2C_ADDR
Synopsis
#define HMC5843_I2C_ADDR 0x3C
Description
HMC5843_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
311
hmc5843_initialize_i2c
Synopsis
CTL_STATUS_t hmc5843_initialize_i2c(CTL_MAGNETOMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
hmc5843_initialize_i2c initializes the magnetometer interface self with methods to communicate with an
HMC5843 magnetometer on the I2C bus bus with 8-bit I2C address addr.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
hmc5843_initialize_i2c returns a standard status code.
Thread Safety
hmc5843_initialize_i2c is thread-safe.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
312
<hmc5883l.h>
Overview
Driver for a Honeywell HMC5883L magnetometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.magneticsensors.com/magnetic-sensor-products.php
http://www.magneticsensors.com/three-axis-digital-compass.php
Datasheet
http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/
Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf
Test hardware
This code has been tested using a SolderCore CoreMag module:
http://soldercore.com/products/sensecore/coremag/
This was plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 75 (continuous), 160 (single)
Range (µT) ±800
Communication up to 400 kHz (I2C)
API SummaryMacros
HMC5883L_I2C_ADDR HMC5883L 8-bit I2C address
Functions
CrossWorks Device Library CrossWorks Device Library
313
hmc5883l_initialize_i2c Initialize HMC5883L on I2C bus
hmc5883l_initialize_transport Initialize sensor on an existing transport
CrossWorks Device Library CrossWorks Device Library
314
HMC5883L_I2C_ADDR
Synopsis
#define HMC5883L_I2C_ADDR 0x3C
Description
HMC5883L_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
315
hmc5883l_initialize_i2c
Synopsis
CTL_STATUS_t hmc5883l_initialize_i2c(CTL_MAGNETOMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
hmc5883l_initialize_i2c initializes the magnetometer interface self with methods to communicate with an
HMC5883L magnetometer on the I2C bus bus with 8-bit I2C address addr.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
hmc5883l_initialize_i2c returns a standard status code.
Thread Safety
hmc5883l_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
316
hmc5883l_initialize_transport
Synopsis
CTL_STATUS_t hmc5883l_initialize_transport(CTL_MAGNETOMETER_t *self, CTL_TRANSPORT_t *transport);
Description
hmc5883l_initialize_transport initializes the magnetometer interface self with methods to communicate with
an HMC5883L magnetometer using the transport transport to transfer I2C data. The transport transport must
already have been initialized with the I2C address of the target HMC5883L.
Return Value
hmc5883l_initialize_transport returns a standard status code.
Thread Safety
hmc5883l_initialize_transport is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
317
<hmc6343.h>
Overview
Driver for a Honeywell HMC6343 digital compass.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.magneticsensors.com/
Datasheet
http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Missiles-
Munitions/HMC6343.pdf
Test hardware
This code has been tested using a SparkFun HMC6343 breakout:
http://www.sparkfun.com/products/8656/
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
HMC6343_I2C_ADDR HMC6343 8-bit I2C address
Functions
hmc6343_read_heading Read heading from compass
CrossWorks Device Library CrossWorks Device Library
318
HMC6343_I2C_ADDR
Synopsis
#define HMC6343_I2C_ADDR 0x32
Description
HMC6343_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
319
hmc6343_read_heading
Synopsis
CTL_STATUS_t hmc6343_read_heading(CTL_I2C_BUS_t *bus, int address, float *heading, float *pitch, float *roll);
Description
hmc6343_read_heading reads the heading, in degrees, from the HMC6352 compass on 8-bit address address
using the I2C bus bus. The heading is written into the float pointed to by heading. Additionally, the pitch and
roll in degrees are written to pitch and roll. heading, pitch, or roll can be null to indicate that the parameter is
not of interest to the client.
The sensor delivers heading, pitch, and roll with resolutions of 0.1 degrees.
Return Value
hmc6343_read_heading returns a standard status code. If the status indicates an error, the returned sample
data is undefined.
Thread Safety
hmc6343_read_heading is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
320
<hmc6352.h>
Overview
Driver for a Honeywell HMC6352 digital compass.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.magneticsensors.com/
Datasheet
http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Missiles-
Munitions/HMC6352.pdf
Test hardware
This code has been tested using a SparkFun HMC6352 breakout:
http://www.sparkfun.com/products/7915/
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Note that the SenseCore's default address was changed from 0x42 to 0x46 by moving the solder jumpers such
that it does not conflict with the HMC6352's default address.
API Summary
Macros
HMC6352_I2C_ADDR HMC6352 8-bit I2C address
Functions
hmc6352_read_heading Read heading from compass
CrossWorks Device Library CrossWorks Device Library
321
HMC6352_I2C_ADDR
Synopsis
#define HMC6352_I2C_ADDR 0x42
Description
HMC6352_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
322
hmc6352_read_heading
Synopsis
CTL_STATUS_t hmc6352_read_heading(CTL_I2C_BUS_t *bus, int address, float *heading);
Description
hmc6352_read_heading reads the heading, in degrees, from the HMC6352 compass on 8-bit address address
using the I2C bus bus. The heading is written into the float pointed to by heading. The sensor delivers headings
with a resolution of 0.1 degrees.
Return Value
hmc6352_read_heading returns a standard status code. If the status indicates an error, the returned sample
data is undefined.
Thread Safety
hmc6352_read_heading is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
323
<mag3110.h>
Overview
Driver for a Freescale MAG3110 magnetometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MAG3110&
Datasheet
http://cache.freescale.com/files/sensors/doc/data_sheet/MAG3110.pdf
Test hardware
This code has been tested using a Freescale LFSTBEB3110 sensor daughterboard:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=LFSTBEB3110
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 0.625, 1.25, 2.5, 5, 10, 20, 40
Range (µT) ±1000
Communication up to 400 kHz (I2C)
API SummaryMacros
MAG3110_I2C_ADDR MAG3110 8-bit I2C address
Functions
mag3110_initialize_i2c Initialize sensor on I2C bus
mag3110_read_die_temperature Read die temperature
CrossWorks Device Library CrossWorks Device Library
324
mag3110_set_oversampling_ratio Set oversampling ratio
CrossWorks Device Library CrossWorks Device Library
325
MAG3110_I2C_ADDR
Synopsis
#define MAG3110_I2C_ADDR 0x1C
Description
MAG3110_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
326
mag3110_initialize_i2c
Synopsis
CTL_STATUS_t mag3110_initialize_i2c(CTL_MAGNETOMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mag3110_initialize_i2c initializes the magnetometer interface self with methods to communicate with a
MAG3110 magnetometer on the I2C bus bus with 8-bit I2C address addr.
Once the magnetometer interface is initialized, you can use all standard magnetometer methods from the
sensor API on the interface.
Return Value
mag3110_initialize_i2c returns a standard status code.
Thread Safety
mag3110_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
327
mag3110_read_die_temperature
Synopsis
CTL_STATUS_t mag3110_read_die_temperature(CTL_MAGNETOMETER_t *self, float *temp);
Description
mag3110_read_die_temperature reads the die temperature of the MAG3110 self.
The die temperature is not returned correctly by the MAG3110. We raised a service request with Freescale
regarding this and their response is as follows:
"Yes, sorry, the die temperature is not being trimmed for MAG3110. This should have been in the errata. What
you are seeing is correct. You can get around this by trimming the output in software since the sensitivity of the
sensor is OK."
Return Value
mag3110_read_die_temperature returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
mag3110_read_die_temperature is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
328
mag3110_set_oversampling_ratio
Synopsis
CTL_STATUS_t mag3110_set_oversampling_ratio(CTL_MAGNETOMETER_t *self, int ratio);
Description
mag3110_set_oversampling_ratio sets the oversampling ration of the MAG3110 self to ratio. ratio should be
16, 32, 64, or 128.
Return Value
mag3110_set_oversampling_ratio returns a standard status code.
Thread Safety
mag3110_set_oversampling_ratio is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
329
<adxl345.h>
Overview
Driver for an Analog Devices ADXL345 3-axis accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.analog.com/en/sensors/inertial-sensors/adxl345/products/product.html
Datasheet
http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
Test hardware
This code has been tested using a SolderCore CoreTilt module:
http://soldercore.com/products/sensecore/coretilt/
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz)0.05, 0.1, 0.2, 0.39, 0.78, 1.56, 3.13, 6.25, 12.5, 25, 50,100, 200, 400, 800, 1600
Range (g) ±2, ±4, ±8, ±16
Communication up to 3.4 MHz (I2C) and 5 MHz (SPI)
API SummaryConstants
ADXL345_I2C_ADDR_ALTERNATE Alternate 8-bit I2C address
ADXL345_I2C_ADDR_DEFAULT Default 8-bit I2C address
Functions
CrossWorks Device Library CrossWorks Device Library
330
adxl345_initialize_i2c Initialize sensor on I2C bus
adxl345_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
331
ADXL345_I2C_ADDR_ALTERNATE
Synopsis
#define ADXL345_I2C_ADDR_ALTERNATE 0xA6
Description
ADXL345_I2C_ADDR_ALTERNATE is the alternate 8-bit I2C address of the ADXL345 sensor with ALT
ADDRESS=0.
CrossWorks Device Library CrossWorks Device Library
332
ADXL345_I2C_ADDR_DEFAULT
Synopsis
#define ADXL345_I2C_ADDR_DEFAULT 0x3A
Description
ADXL345_I2C_ADDR_DEFAULT is the default 8-bit I2C address of the ADXL345 sensor with ALT ADDRESS=1.
CrossWorks Device Library CrossWorks Device Library
333
adxl345_initialize_i2c
Synopsis
CTL_STATUS_t adxl345_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
adxl345_initialize_i2c initializes the accelerometer interface self with methods to communicate with an
ADXL345 accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
adxl345_initialize_i2c returns a standard status code.
Thread Safety
adxl345_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
334
adxl345_initialize_spi
Synopsis
CTL_STATUS_t adxl345_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
adxl345_initialize_spi initializes the accelerometer interface self with methods to communicate with an
ADXL345 accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI
mode 0. The maximum clock speed supported by the ADXL345 in SPI mode is 5 MHz: you can increase the clock
speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
adxl345_initialize_spi returns a standard status code.
Thread Safety
adxl345_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
335
<adxl362.h>
Overview
Driver for an Analog Devices ADXL362 3-axis accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.analog.com/en/mems-sensors/mems-accelerometers/adxl362/products/product.html
Datasheet
http://www.analog.com/static/imported-files/data_sheets/ADXL362.pdf
Test hardware
This code has been tested using a SparkFun ADXL362 breakout:
http://www.sparkfun.com/products/11446
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 12.5, 25, 50, 100 (default), 200, 400
Range (g) ±2, ±4, ±8
Communication 1 MHz to 5 MHz (SPI)
API Summary
Functions
adxl362_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
336
adxl362_initialize_spi
Synopsis
CTL_STATUS_t adxl362_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
adxl362_initialize_spi initializes the accelerometer interface self with methods to communicate with an
ADXL362 accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI
mode 0. The maximum clock speed supported by the ADXL362 in SPI mode is 5 MHz: you can increase the clock
speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
adxl362_initialize_spi returns a standard status code.
Thread Safety
adxl362_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
337
<atavrsbin1.h>
Overview
Driver for Atmel Inertial One ATAVRSBIN1 board.
The Inertial One board provides a BMA150 accelerometer, an ITG-3200 gyroscope, and an AK8975
magnetometer on a common I2C bus.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.atmel.com/products/microcontrollers/avr/sensors_xplain.aspx
Test hardware
This code has been tested using a ATAVRSBIN1 sensor wire-wrapped to a protoshield and on a SolderCore.
See Also
<bma150.h>, <itg3200.h>, <ak8975.h>
API Summary
Types
ATAVRSBIN1_t Sensor group
Functions
atavrsbin1_initialize_i2c Initialize sensor group on I2C bus
CrossWorks Device Library CrossWorks Device Library
338
ATAVRSBIN1_t
Synopsis
typedef struct { CTL_IMU_t core; CTL_ACCELEROMETER_t accel; CTL_GYROSCOPE_t gyro; CTL_MAGNETOMETER_t mag;} ATAVRSBIN1_t;
Description
ATAVRSBIN1_t contains the instance data for the Inertial One sensor group.
Structure
core
The core IMU structure. The IMU structure is initialized with pointers to the gyro, accel, and mag members.
accel
The accelerometer instance containing the state of the BMA150.
gyro
The gyroscope instance containing the state of the ITG-3200.
mag
The magnetometer instance containing the state of the AK8975.
CrossWorks Device Library CrossWorks Device Library
339
atavrsbin1_initialize_i2c
Synopsis
CTL_STATUS_t atavrsbin1_initialize_i2c(ATAVRSBIN1_t *self, CTL_I2C_BUS_t *bus);
Description
atavrsbin1_initialize_i2c initializes the BMA150 accelerometer, ITG-3200 gyroscope, and AK8975 magnetometer
on the I2C bus bus using factory I2C addresses. When complete, the the IMU member core is initialized pointing
to the appropriate members within self.
Return Value
atavrsbin1_initialize_i2c returns a standard status code.
Thread Safety
atavrsbin1_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
340
<atavrsbin2.h>
Overview
Driver for Atmel Inertial Two ATAVRSBIN2 board.
The Inertial Two board provides a KXTF9 accelerometer, an an IMU-3000 gyroscope, and an HMC5883L
magnetometer on a common I2C bus.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.atmel.com/products/microcontrollers/avr/sensors_xplain.aspx
Test hardware
This code has been tested using a ATAVRSBIN2 sensor wire-wrapped to a protoshield and on a SolderCore.
See Also
<kxtf9.h>, <imu3000.h>, <hmc5883l.h>
API Summary
Types
ATAVRSBIN2_t Sensor group
Functions
atavrsbin2_initialize_i2c Initialize sensor group on I2C bus
CrossWorks Device Library CrossWorks Device Library
341
ATAVRSBIN2_t
Synopsis
typedef struct { CTL_IMU_t core; CTL_ACCELEROMETER_t accel; CTL_GYROSCOPE_t gyro; CTL_MAGNETOMETER_t mag;} ATAVRSBIN2_t;
Description
ATAVRSBIN2_t contains the instance data for the Inertial One sensor group.
Structure
core
The core IMU structure. The IMU structure is initialized with pointers to the gyro, accel, and mag members.
accel
The accelerometer instance containing the state of the KXTF9.
gyro
The gyroscope instance containing the state of the IMU-3000.
mag
The magnetometer instance containing the state of the HMC5883L.
CrossWorks Device Library CrossWorks Device Library
342
atavrsbin2_initialize_i2c
Synopsis
CTL_STATUS_t atavrsbin2_initialize_i2c(ATAVRSBIN2_t *self, CTL_I2C_BUS_t *bus);
Description
atavrsbin2_initialize_i2c initializes the KXTF9 accelerometer, IMU-3000 gyroscope, and HMC5883L
magnetometer on the I2C bus bus using factory I2C addresses. When complete, the the IMU member core is
initialized pointing to the appropriate members within self.
Return Value
atavrsbin2_initialize_i2c returns a standard status code.
Thread Safety
atavrsbin2_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
343
<bma150.h>
Overview
Driver for Bosch Sensortec BMA150 3-axis accelerometer.
This driver assumes that the BMA150 will always runs with the shadow registers enabled, i.e. that the
shadow_dis bit in the second configuration register is zero. If you wish to run with the shadow registers
disabled, you will need to write your own replacement driver.
Note that this also works for an SMB380 accelerometer which has the same register interface as the BMA150.
BMA150 Resources
Web page
http://www.bosch-sensortec.com/homepage/products_3/3_axis_sensors/acceleration_sensors/bma150_4/
bma150
Datasheet
http://ae-bst.resource.bosch.com/media/products/dokumente/bma150/bst-bma150-ds000-07.pdf
Test hardware
This code has been tested using an Atmel ATAVRSBIN Inertial One Xplain board:
http://store.atmel.com/PartDetail.aspx?q=p:10500250#tc:description
The module was wire-wrapped on a prototyping shield and installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 25, 50, 100, 190, 375, 750, 1500
Range (g) ±2, ±4, ±8
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
SMB380 Resources
Datasheet
http://www.olimex.com/dev/pdf/OTHER/BMA150_Preliminary_Datasheet_Rev13_20070918.pdf
CrossWorks Device Library CrossWorks Device Library
344
Test hardware
This code has been tested using an Olimex MOD-SMB380:
http://www.olimex.com/Products/Modules/Accel/MOD-SMB380/
This is plugged into a custom CoreProto rivet and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
BMA150_I2C_ADDR BMA150 8-bit I2C address
Functions
bma150_initialize_i2c Initialize sensor on I2C bus
bma150_initialize_spi Initialize sensor on SPI bus
bma150_read_chip_id Read chip ID register
bma150_read_die_temperature Read temperature
bma150_soft_reset Soft-reset the sensor
CrossWorks Device Library CrossWorks Device Library
345
BMA150_I2C_ADDR
Synopsis
#define BMA150_I2C_ADDR 0x70
Description
BMA150_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
346
bma150_initialize_i2c
Synopsis
CTL_STATUS_t bma150_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
bma150_initialize_i2c initializes the accelerometer interface self with methods to communicate with a BMA150
accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
bma150_initialize_i2c returns a standard status code.
Thread Safety
bma150_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
347
bma150_initialize_spi
Synopsis
CTL_STATUS_t bma150_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
bma150_initialize_spi initializes the accelerometer interface self with methods to communicate with an
BMA150 accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI
mode 0. The maximum clock speed supported by the BMA150 in SPI mode is 10 MHz: you can increase the clock
speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
bma150_initialize_spi returns a standard status code.
Thread Safety
bma150_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
348
bma150_read_chip_id
Synopsis
CTL_STATUS_t bma150_read_chip_id(CTL_ACCELEROMETER_t *self);
Description
bma150_read_chip_id reads the chip ID register of the BMA150 accelerometer self.
Return Value
bma150_read_chip_id returns an extended status code: non-negative values indicate a successful read, and
value, of the chip ID.
Thread Safety
bma150_read_chip_id is thread-safe if the transport member in self is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
349
bma150_read_die_temperature
Synopsis
CTL_STATUS_t bma150_read_die_temperature(CTL_ACCELEROMETER_t *self, float *temp);
Description
bma150_read_die_temperature reads the sensor's internal temperature register and writes the temperature, in
degrees Celsius, to the float pointed to by temp.
Return Value
bma150_read_die_temperature returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
bma150_read_die_temperature is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
350
bma150_soft_reset
Synopsis
CTL_STATUS_t bma150_soft_reset(CTL_ACCELEROMETER_t *self);
Description
bma150_soft_reset performs a soft reset of the sensor self.
Return Value
bma150_soft_reset returns a standard status code.
Thread Safety
bma150_soft_reset is thread-safe if the transport member in self is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
351
<bma250.h>
Overview
Driver for Bosch Sensortec BMA250 3-axis accelerometer.
Resources
Web page
http://www.bosch-sensortec.com/en/homepage/products_3/3_axis_sensors/acceleration_sensors/
bma250_1/bma250
Datasheet
http://ae-bst.resource.bosch.com/media/products/dokumente/bma250/BST-BMA250-DS002-05.pdf
Test hardware
This code has been tested using an Olimex STM32-405STK:
https://www.olimex.com/Products/ARM/ST/STM32-405STK/
Specification
Parameter Supported settings
Bandwidth (Hz) 8, 16, 31, 63, 125, 250, 500, 1000
Range (g) ±2, ±4, ±8, ±16
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API Summary
Macros
BMA250_I2C_ADDR BMA250 8-bit I2C address
Functions
bma250_initialize_i2c Initialize sensor on I2C bus
bma250_initialize_spi Initialize sensor on SPI bus
bma250_read_chip_id Read chip ID register
bma250_read_die_temperature Read temperature
CrossWorks Device Library CrossWorks Device Library
352
BMA250_I2C_ADDR
Synopsis
#define BMA250_I2C_ADDR(SDO) (0x30 + (SDO)*2)
Description
BMA250_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet, with SDO
pulled low (0) or high (1).
CrossWorks Device Library CrossWorks Device Library
353
bma250_initialize_i2c
Synopsis
CTL_STATUS_t bma250_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
bma250_initialize_i2c initializes the accelerometer interface self with methods to communicate with a BMA250
accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
bma250_initialize_i2c returns a standard status code.
Thread Safety
bma250_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
354
bma250_initialize_spi
Synopsis
CTL_STATUS_t bma250_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
bma250_initialize_spi initializes the accelerometer interface self with methods to communicate with an
BMA250 accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI
mode 0. The maximum clock speed supported by the BMA250 in SPI mode is 10 MHz: you can increase the clock
speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
bma250_initialize_spi returns a standard status code.
Thread Safety
bma250_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
355
bma250_read_chip_id
Synopsis
CTL_STATUS_t bma250_read_chip_id(CTL_ACCELEROMETER_t *self);
Description
bma250_read_chip_id reads the chip ID register of the BMA250 accelerometer self.
Return Value
bma250_read_chip_id returns an extended status code: non-negative values indicate a successful read, and
value, of the chip ID.
Thread Safety
bma250_read_chip_id is thread-safe if the transport member in self is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
356
bma250_read_die_temperature
Synopsis
CTL_STATUS_t bma250_read_die_temperature(CTL_ACCELEROMETER_t *self, float *temp);
Description
bma250_read_die_temperature reads the sensor's internal temperature register and writes the temperature, in
degrees Celsius, to the float pointed to by temp.
Return Value
bma250_read_die_temperature returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
bma250_read_die_temperature is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
357
<imu3000.h>
Overview
Driver for InvenSense IMU-3000 gyroscope.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://invensense.com/mems/gyro/imu3000.html
Datasheet
http://invensense.com/mems/gyro/documents/RM-IMU-3000A.pdf
Test hardware
This code has been tested using a SparkFun IMU-3000 breakout:
http://www.sparkfun.com/products/10251
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 8,000 to 31.25 in 256 division steps.
Range (dps) 250, 500, 1000, 2000 (default)
Communication up to 400 kHz (I2C)
API SummaryMacros
IMU3000_I2C_ADDR IMU-3000 8-bit I2C address selected with AD0 signal
Functions
imu3000_initialize_i2c Initialize sensor on I2C bus
imu3000_read_die_temperature Read die temperature
CrossWorks Device Library CrossWorks Device Library
358
IMU3000_I2C_ADDR
Synopsis
#define IMU3000_I2C_ADDR(AD0) (0xD0 + 2*(AD0))
CrossWorks Device Library CrossWorks Device Library
359
imu3000_initialize_i2c
Synopsis
CTL_STATUS_t imu3000_initialize_i2c(CTL_GYROSCOPE_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
imu3000_initialize_i2c initializes the gyroscope interface self with methods to communicate with an IMU-3000
gyroscope on the I2C bus bus with 8-bit I2C address addr.
Once the gyroscope interface is initialized, you can use all standard gyroscope methods from the sensor API on
the interface.
Return Value
imu3000_initialize_i2c returns a standard status code.
Thread Safety
imu3000_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
360
imu3000_read_die_temperature
Synopsis
CTL_STATUS_t imu3000_read_die_temperature(CTL_GYROSCOPE_t *self, float *temp);
Description
this reads the die temperature of the IMU-3000 into temp.
Return Value
imu3000_read_die_temperature returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
imu3000_read_die_temperature is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
361
<imu3000_combo.h>
Overview
Driver for a SparkFun IMU-3000 Combo IMU.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.sparkfun.com/products/10121
Test hardware
This code has been tested using a SparkFun IMU-3000 Combo:
http://www.sparkfun.com/products/10121
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
See Also
<imu3000.h>, <adxl345.h>
API Summary
Types
IMU3000_COMBO_t Sensor group
Functions
imu3000_combo_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
362
IMU3000_COMBO_t
Synopsis
typedef struct { CTL_IMU_t core; CTL_GYROSCOPE_t gyro; CTL_ACCELEROMETER_t accel; int __passthrough;} IMU3000_COMBO_t;
Description
IMU3000_COMBO_t contains the instance data for the IMU-3000 Combo sensor group.
Structure
core
The core IMU structure. The IMU structure is initialized with pointers to the gyro and accel members with
the manetometer mag set to zero.
accel
The accelerometer instance containing the state of the BMA150.
gyro
The gyroscope instance containing the state of the ITG-3200.
__passthrough
Private member: flag indicating auxiliary I2C bus is in pass-through mode.
CrossWorks Device Library CrossWorks Device Library
363
imu3000_combo_initialize_i2c
Synopsis
CTL_STATUS_t imu3000_combo_initialize_i2c(IMU3000_COMBO_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
imu3000_combo_initialize_i2c initializes the ADXL345 accelerometer and IMU-3000 gyroscope, the I2C bus
bus using appropriate I2C addresses. The address addr is the address of the IMU-3000; the ADXL345's address is
fixed by hardware. When complete, the the IMU member core is initialized pointing to the appropriate members
within self.
imu3000_combo_initialize_i2c takes care of correcting the alignment of the accelerometer axes with respect to
the gyroscope.
Note
Once initialized, you can set the accelerometer's range and bandwidth, but you must do this before taking any
accelerometer measurements. Once an accelerometer measurement is taken, you cannot change the bandwidth
or range of the accelerometer because the accelerometer is under control of the IMU-3000. We have not found
a clean way to shut down autonomous reading by the IMU-3000 such that the auxiliary I2C bus can be placed in
bypass mode and the accelerometer reconfigured.
Return Value
imu3000_combo_initialize_i2c returns a standard status code.
Thread Safety
imu3000_combo_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
CrossWorks Device Library CrossWorks Device Library
364
<itg3200.h>
Overview
Driver for InvenSense ITG-3200 gyroscope.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://invensense.com/mems/gyro/itg3200.html
Datasheet
http://invensense.com/mems/gyro/documents/RM-ITG-3200A.pdf
Test hardware
This code has been tested using a SolderCore CoreGyro module:
http://soldercore.com/products/sensecore/coregyro/
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 8 kHz to 31.25 Hz in 256 division steps.
Range (dps) 2000 (fixed)
Communication up to 400 kHz (I2C)
API SummaryMacros
ITG3200_I2C_ADDR ITG-3200 8-bit I2C address selected with AD0 signal
Functions
itg3200_initialize_i2c Initialize sensor on I2C bus
itg3200_read_die_temperature Read die temperature
CrossWorks Device Library CrossWorks Device Library
365
ITG3200_I2C_ADDR
Synopsis
#define ITG3200_I2C_ADDR(AD0) (0xD0 + 2*(AD0))
CrossWorks Device Library CrossWorks Device Library
366
itg3200_initialize_i2c
Synopsis
CTL_STATUS_t itg3200_initialize_i2c(CTL_GYROSCOPE_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
itg3200_initialize_i2c initializes the gyroscope interface self with methods to communicate with an ITG-3200
gyroscope on the I2C bus bus with 8-bit I2C address addr.
Once the gyroscope interface is initialized, you can use all standard gyroscope methods from the sensor API on
the interface.
Return Value
itg3200_initialize_i2c returns a standard status code.
Thread Safety
itg3200_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
367
itg3200_read_die_temperature
Synopsis
CTL_STATUS_t itg3200_read_die_temperature(CTL_GYROSCOPE_t *self, float *temp);
Description
this reads the die temperature of the ITG-3200 into temp.
Return Value
itg3200_read_die_temperature returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
itg3200_read_die_temperature is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
368
<kxp84.h>
Overview
Driver for Kionix KXP84 3-axis accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.kionix.com/accelerometers/kxp84
Datasheet
http://www.kionix.com/Product-Specs/KXP84-2050%20Specifications%20Rev%202.pdf
Test hardware
This code has been tested using a Kionix KXP84-2050 Evaluation Board:
http://www.kionix.com/Downloads/KXP84%20Evaluation%20Board.pdf — Layout
http://www.kionix.com/Downloads/KXP84%20Eval%20Schematic.pdf — Schematic
This was hand wired to a SolderCore:
http://www.soldercore.com/
Specification
Parameter Supported settings
Bandwidth (Hz) Set by filter capacitors
Range (g) ±2 (fixed)
Communication up to 400 kHz (I2C) and 1 MHz (SPI)
API Summary
Macros
KXP84_I2C_ADDR KXP84 8-bit I2C address selected by ADDR0 input
Functions
kxp84_initialize_i2c Initialize sensor on I2C bus
kxp84_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
369
KXP84_I2C_ADDR
Synopsis
#define KXP84_I2C_ADDR(ADDR0) (0x30 + 2*(ADDR0))
CrossWorks Device Library CrossWorks Device Library
370
kxp84_initialize_i2c
Synopsis
CTL_STATUS_t kxp84_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
kxp84_initialize_i2c initializes the accelerometer interface self with methods to communicate with a KXP84
accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
kxp84_initialize_i2c returns a standard status code.
Thread Safety
kxp84_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
371
kxp84_initialize_spi
Synopsis
CTL_STATUS_t kxp84_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
kxp84_initialize_spi initializes the accelerometer interface self with methods to communicate with a KXP84
accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI mode 0.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
kxp84_initialize_spi returns a standard status code.
Thread Safety
kxp84_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
CrossWorks Device Library CrossWorks Device Library
372
<kxtf9.h>
Overview
Driver for a Kionix KXTF9 3-axis accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.kionix.com/accelerometers/kxtf9
Datasheet
http://www.kionix.com/sites/default/files/KXTF9-1026%20Specifications%20Rev%206.pdf
Test hardware
This code has been tested using an ATAVRSBIN2 Inertial Evaluation Board and a MEGA-1284P Xplained board.
Specification
Parameter Supported settings
Bandwidth (Hz) No configurable
Range (g) ±2, ±4, ±8
Communication up to 400 kHz (I2C)
API Summary
Macros
KXTF9_I2C_ADDR KXTF9 8-bit I2C address
Functions
kxtf9_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
373
KXTF9_I2C_ADDR
Synopsis
#define KXTF9_I2C_ADDR 0x1E
Description
KXTF9_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
374
kxtf9_initialize_i2c
Synopsis
CTL_STATUS_t kxtf9_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
kxtf9_initialize_i2c initializes the accelerometer interface self with methods to communicate with a KXTF9
accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
kxtf9_initialize_i2c returns a standard status code.
Thread Safety
kxtf9_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
375
<l3g4200d.h>
Overview
Driver for an STMicroelectronics L3G4200D 3-axis gyroscope.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/internet/analog/product/250373.jsp
Datasheet
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/
CD00265057.pdf
Test hardware
This code has been tested using a SparkFun L3G4200D Breakout:
http://www.sparkfun.com/products/10612
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 100, 200, 400, 800
Range (dps) 250, 500, 2000
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API SummaryMacros
L3G4200D_I2C_ADDR L3G4200D 8-bit I2C address selected with SDO signal
Functions
l3g4200d_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
376
L3G4200D_I2C_ADDR
Synopsis
#define L3G4200D_I2C_ADDR(SDO) (0xD0 + 2*(SDO))
CrossWorks Device Library CrossWorks Device Library
377
l3g4200d_initialize_i2c
Synopsis
CTL_STATUS_t l3g4200d_initialize_i2c(CTL_GYROSCOPE_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
l3g4200d_initialize_i2c initializes the gyroscope interface self with methods to communicate with an
L3G4200D gyroscope on the I2C bus bus with 8-bit I2C address addr.
Once the gyroscope interface is initialized, you can use all standard gyroscope methods from the sensor API on
the interface.
Return Value
l3g4200d_initialize_i2c returns a standard status code.
Thread Safety
l3g4200d_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
378
<l3gd20.h>
Overview
Driver for an STMicroelectronics L3GD20 3-axis gyroscope.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/web/catalog/sense_power/FM89/SC1288/PF252443
Datasheet
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00036465.pdf
Test hardware
This code has been tested using an Olimex MOD-L3GD20:
https://www.olimex.com/Products/Modules/Sensors/MOD-L3GD20/
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 95, 190, 380, 760
Range (dps) 250, 500, 2000
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API Summary
Macros
L3GD20_I2C_ADDR L3GD20 8-bit I2C address selected with SDO signal
Functions
l3gd20_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
379
L3GD20_I2C_ADDR
Synopsis
#define L3GD20_I2C_ADDR(SDO) (0xD4 + 2*(SDO))
CrossWorks Device Library CrossWorks Device Library
380
l3gd20_initialize_i2c
Synopsis
CTL_STATUS_t l3gd20_initialize_i2c(CTL_GYROSCOPE_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
l3gd20_initialize_i2c initializes the gyroscope interface self with methods to communicate with an L3GD20
gyroscope on the I2C bus bus with 8-bit I2C address addr.
Once the gyroscope interface is initialized, you can use all standard gyroscope methods from the sensor API on
the interface.
Return Value
l3gd20_initialize_i2c returns a standard status code.
Thread Safety
l3gd20_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
381
<lis302dl.h>
Overview
Driver for STMicroelectronics LIS302DL 3-axis accelerometer in SPI or I2C mode.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/internet/analog/product/152913.jsp
Datasheet
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/
CD00135460.pdf
Test hardware
This code has been tested using a SparkFun LIS302DL breakout:
http://www.sparkfun.com/products/8658
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 100, 400
Range (g) ±2, ±8
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API SummaryMacros
LIS302DL_I2C_ADDR LIS302DL 8-bit I2C address selected with SDO signal
Functions
lis302dl_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
382
lis302dl_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
383
LIS302DL_I2C_ADDR
Synopsis
#define LIS302DL_I2C_ADDR(SDO) (0x38 + 2*(SDO))
CrossWorks Device Library CrossWorks Device Library
384
lis302dl_initialize_i2c
Synopsis
CTL_STATUS_t lis302dl_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lis302dl_initialize_i2c initializes the accelerometer interface self with methods to communicate with a LIS302DL
accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis302dl_initialize_i2c returns a standard status code.
Thread Safety
lis302dl_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C transports,
you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
385
lis302dl_initialize_spi
Synopsis
CTL_STATUS_t lis302dl_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *spi);
Description
lis302dl_initialize_spi initializes the accelerometer interface self with methods to communicate with a LIS302DL
accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI mode 0.
The maximum clock speed supported by the LIS302DL in SPI mode is 10 MHz: you can increase the clock speed
from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis302dl_initialize_spi returns a standard status code.
Thread Safety
lis302dl_initialize_spi is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C transports,
you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
386
<lis331dlh.h>
Overview
Driver for STMicroelectronics LIS331DLH 3-axis accelerometer in SPI or I2C mode.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/internet/analog/product/218132.jsp
Datasheet
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/
CD00213470.pdf
Test hardware
This code has been tested using a SparkFun LSM303DLH breakout:
http://www.sparkfun.com/products/10703
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 50, 100, 400, 1000
Range (g) ±2, ±4, ±8
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API SummaryMacros
LIS331DLH_I2C_ADDR LIS331DLH 8-bit I2C address selected with SA0 signal
LIS331DLH Accelerometer
lis331dlh_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
387
lis331dlh_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
388
LIS331DLH_I2C_ADDR
Synopsis
#define LIS331DLH_I2C_ADDR(SDO) (0x30 + 2*(SDO))
CrossWorks Device Library CrossWorks Device Library
389
lis331dlh_initialize_i2c
Synopsis
CTL_STATUS_t lis331dlh_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lis331dlh_initialize_i2c initializes the accelerometer interface self with methods to communicate with a
LIS331DLH accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis331dlh_initialize_i2c returns a standard status code.
Thread Safety
lis331dlh_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
390
lis331dlh_initialize_spi
Synopsis
CTL_STATUS_t lis331dlh_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *spi);
Description
lis331dlh_initialize_spi initializes the accelerometer interface self with methods to communicate with a
LIS331DLH accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit
SPI mode 0. The maximum clock speed supported by the LIS331DLH in SPI mode is 10 MHz: you can increase the
clock speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis331dlh_initialize_spi returns a standard status code.
Thread Safety
lis331dlh_initialize_spi is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
391
<lis331hh.h>
Overview
Driver for STMicroelectronics LIS331HH 3-axis accelerometer in SPI or I2C mode.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/internet/analog/product/247976.jsp
Datasheet
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/
CD00250937.pdf
Test hardware
This code has been tested using a SparkFun LIS331HH breakout:
http://www.sparkfun.com/products/10345
This was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 50, 100, 400, 1000
Range (g) ±6, ±12, ±24
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API SummaryMacros
LIS331HH_I2C_ADDR LIS331HH 8-bit I2C address selected with SA0 signal
LIS331HH Accelerometer
lis331hh_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
392
lis331hh_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
393
LIS331HH_I2C_ADDR
Synopsis
#define LIS331HH_I2C_ADDR(SDO) (0x30 + 2*(SDO))
CrossWorks Device Library CrossWorks Device Library
394
lis331hh_initialize_i2c
Synopsis
CTL_STATUS_t lis331hh_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lis331hh_initialize_i2c initializes the accelerometer interface self with methods to communicate with a
LIS331HH accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis331hh_initialize_i2c returns a standard status code.
Thread Safety
lis331hh_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
395
lis331hh_initialize_spi
Synopsis
CTL_STATUS_t lis331hh_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *spi);
Description
lis331hh_initialize_spi initializes the accelerometer interface self with methods to communicate with a
LIS331HH accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit
SPI mode 0. The maximum clock speed supported by the LIS331HH in SPI mode is 10 MHz: you can increase the
clock speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis331hh_initialize_spi returns a standard status code.
Thread Safety
lis331hh_initialize_spi is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
396
<lis3dsh.h>
Overview
Driver for STMicroelectronics LIS3DSH 3-axis accelerometer in SPI or I2C mode.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/web/catalog/sense_power/FM89/SC444/PF252716
Datasheet
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00040962.pdf
Test hardware
This code has been tested using a STM32F4DISCOVERY board:
http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF252419
Specification
Parameter Supported settings
Bandwidth (Hz) 50, 200, 400, 800
Range (g) ±2, ±4, ±6, ±8, ±16
Communication up to 400 kHz (I2C) and 10 MHz (SPI)
API Summary
Macros
LIS3DSH_I2C_ADDR LIS3DSH 8-bit I2C address selected with SDO signal
Functions
lis3dsh_initialize_i2c Initialize sensor on I2C bus
lis3dsh_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
397
LIS3DSH_I2C_ADDR
Synopsis
#define LIS3DSH_I2C_ADDR(SDO) (0x38 + 2*(SDO))
CrossWorks Device Library CrossWorks Device Library
398
lis3dsh_initialize_i2c
Synopsis
CTL_STATUS_t lis3dsh_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lis3dsh_initialize_i2c initializes the accelerometer interface self with methods to communicate with a LIS3DSH
accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis3dsh_initialize_i2c returns a standard status code.
Thread Safety
lis3dsh_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C transports,
you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
399
lis3dsh_initialize_spi
Synopsis
CTL_STATUS_t lis3dsh_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *spi);
Description
lis3dsh_initialize_spi initializes the accelerometer interface self with methods to communicate with a LIS3DSH
accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit SPI mode 0.
The maximum clock speed supported by the LIS3DSH in SPI mode is 10 MHz: you can increase the clock speed
from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis3dsh_initialize_spi returns a standard status code.
Thread Safety
lis3dsh_initialize_spi is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C transports,
you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
400
<lis3lv02dl.h>
Overview
Driver for STMicroelectronics LIS3LV02DL 3-axis accelerometer in SPI or I2C mode.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.st.com/web/catalog/sense_power/FM89/SC444/PF127514
Datasheet
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00091417.pdf
Test hardware
This code has been tested using an Olimex STM32-LCD which has an on-board LIS3LV02DL:
http://www.olimex.com/Products/ARM/ST/STM32-LCD/
Specification
Parameter Supported settings
Bandwidth (Hz) 40, 160, 640, 2560
Range (g) ±2, ±6
Communication up to 400 kHz (I2C) and 8 MHz (SPI)
API Summary
Macros
LIS3LV02DL_I2C_ADDR LIS3LV02DL 8-bit I2C address
Functions
lis3lv02dl_initialize_i2c Initialize sensor on I2C bus
lis3lv02dl_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
401
LIS3LV02DL_I2C_ADDR
Synopsis
#define LIS3LV02DL_I2C_ADDR 0x3A
CrossWorks Device Library CrossWorks Device Library
402
lis3lv02dl_initialize_i2c
Synopsis
CTL_STATUS_t lis3lv02dl_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
lis3lv02dl_initialize_i2c initializes the accelerometer interface self with methods to communicate with a
LIS3LV02DL accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis3lv02dl_initialize_i2c returns a standard status code.
Thread Safety
lis3lv02dl_initialize_i2c is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
403
lis3lv02dl_initialize_spi
Synopsis
CTL_STATUS_t lis3lv02dl_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *spi);
Description
lis3lv02dl_initialize_spi initializes the accelerometer interface self with methods to communicate with a
LIS3VL02DL accelerometer on the SPI bus associated with dev. The protocol for device dev is set to 1 MHz, 8-bit
SPI mode 0. The maximum clock speed supported by the LIS3LV02DL in SPI mode is 8 MHz: you can increase the
clock speed from the initial 1 MHz using ctl_spi_set_speed.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
lis3lv02dl_initialize_spi returns a standard status code.
Thread Safety
lis3lv02dl_initialize_spi is thread-safe if the transport transport is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
404
<mma7455l.h>
Overview
Driver for a Freescale MMA7455L accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
MMA745xL
Datasheet
MMA8451Q
Test hardware
This code has been tested using an Embedded Artists LPC1788-OEM module on the EA OEM Base Board.
Specification
Parameter Supported settings
Bandwidth (Hz) 62.5, 125
Range (g) ±2, ±4, ±8
Communication up to 400 kHz (I2C), 8 MHz (SPI)
API Summary
Macros
MMA7455_I2C_ADDR MMA7455L 8-bit I2C address
Functions
mma7455l_initialize_i2c Initialize sensor on I2C bus
mma7455l_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
405
MMA7455_I2C_ADDR
Synopsis
#define MMA7455_I2C_ADDR 0x3A
CrossWorks Device Library CrossWorks Device Library
406
mma7455l_initialize_i2c
Synopsis
CTL_STATUS_t mma7455l_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mma7455l_initialize_i2c initializes the accelerometer interface self with methods to communicate with an
MMA7455L accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
mma7455l_initialize_i2c returns a standard status code.
Thread Safety
mma7455l_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
407
mma7455l_initialize_spi
Synopsis
CTL_STATUS_t mma7455l_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev);
Description
mma7455l_initialize_spi initializes the accelerometer interface self with methods to communicate with an
MMA7455L accelerometer using the device dev.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
mma7455l_initialize_spi returns a standard status code.
Thread Safety
mma7455l_initialize_spi is thread-safe if a mutex is associated with the device dev.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
408
<mma7660fc.h>
Overview
Driver for a Freescale MMA7660FC accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MMA7660FC
Datasheet
http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7660FC.pdf
Test hardware
This code has been tested using a Seeed Studio MMA7660FC module:
http://www.seeedstudio.com/depot/grove-3axis-digital-accelerometer15g-p-765.html?cPath=144_146
This was attached to a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) Not configurable.
Range (g) ±1.5 (fixed)
Communication up to 400 kHz (I2C)
API Summary
Macros
MMA7660FC_I2C_ADDR MMA7660FC 8-bit I2C address
Functions
mma7660fc_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
409
MMA7660FC_I2C_ADDR
Synopsis
#define MMA7660FC_I2C_ADDR 0x98
Description
MMA7660FC_I2C_ADDR defines the default 8-bit I2C address for the device as specified in the datasheet.
CrossWorks Device Library CrossWorks Device Library
410
mma7660fc_initialize_i2c
Synopsis
CTL_STATUS_t mma7660fc_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mma7660fc_initialize_i2c initializes the accelerometer interface self with methods to communicate with an
MMA7660FC accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
mma7660fc_initialize_i2c returns a standard status code.
Thread Safety
mma7660fc_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
411
<mma845xq.h>
Overview
Driver for a Freescale MMA845xQ accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
MMA8451Q
MMA8452Q
MMA8453Q
Datasheet
MMA8451Q
MMA8452Q
MMA8453Q
Test hardware
This code has been tested using a Freescale LFSTBEB3110 sensor daughterboard:
http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=LFSTBEB3110
The sensor was wired to a CoreProto and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 1.56, 6.25, 12.5, 50, 100, 200, 400, 800
Range (g) ±2, ±4, ±8
Communication up to 2.25 MHz (I2C)
CrossWorks Device Library CrossWorks Device Library
412
API Summary
Macros
MMA8451Q_I2C_ADDR MMA845xQ 8-bit I2C address selected with SA0 signal
Functions
mma8451q_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
413
MMA8451Q_I2C_ADDR
Synopsis
#define MMA8451Q_I2C_ADDR(SA0) (0x38 + 2*(SA0))
CrossWorks Device Library CrossWorks Device Library
414
mma8451q_initialize_i2c
Synopsis
CTL_STATUS_t mma8451q_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mma8451q_initialize_i2c initializes the accelerometer interface self with methods to communicate with an
MMA845xQ accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
mma8451q_initialize_i2c returns a standard status code.
Thread Safety
mma8451q_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
415
<mma8491q.h>
Overview
Driver for a Freescale MMA8491Q accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
MMA8491Q
Datasheet
MMA8491Q
Test hardware
This code has been tested using an eLement-14/Freescale XTRINSIC-SENSORS-EVK:
http://uk.farnell.com/freescale-semiconductor/xtrinsic-sensors-evk/evaluation-kit-xtrinsic-sensor/
dp/2308734
This was wired to a CoreStack and installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Parameter Supported settings
Bandwidth (Hz) 1.56, 6.25, 12.5, 50, 100, 200, 400, 800
Range (g) ±8
Communication 400 kHz (I2C)
API Summary
Macros
MMA8491Q_I2C_ADDR MMA8491Q 8-bit I2C address
Functions
mma8491q_initialize_i2c Initialize sensor on I2C bus
CrossWorks Device Library CrossWorks Device Library
416
MMA8491Q_I2C_ADDR
Synopsis
#define MMA8491Q_I2C_ADDR 0xAA
CrossWorks Device Library CrossWorks Device Library
417
mma8491q_initialize_i2c
Synopsis
CTL_STATUS_t mma8491q_initialize_i2c(MMA8491Q_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr, CTL_STATUS_t write_en *self, int);
Description
mma8491q_initialize_i2c initializes the accelerometer interface self with methods to communicate with an
MMA8491Q accelerometer on the I2C bus bus with 8-bit I2C address addr.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
mma8491q_initialize_i2c returns a standard status code.
Thread Safety
mma8491q_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
418
<mpu6000.h>
Overview
Driver for InvenSense MPU-6000 and MPU-6050 IMUs.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://invensense.com/mems/gyro/mpu6050.html
Datasheet
http://invensense.com/mems/gyro/documents/RM-MPU-6000A.pdf
Test hardware
This code has been tested using a SolderCore CoreMPU module:
http://soldercore.com/products/sensecore/corempu/
This was plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
API Summary
Macros
MPU6000_I2C_ADDR MPU-6000 8-bit I2C address selected with AD0 signal
Types
MPU6000_t Sensor group
Functions
mpu6000_aux_transport_setup Initialize transport on auxiliary I2C bus
mpu6000_initialize_i2c Initialize sensor on I2C bus
mpu6000_initialize_spi Initialize sensor on SPI bus
mpu6000_read_die_temperature Read die temperature
mpu6000_revision Decode device and silicon revision
CrossWorks Device Library CrossWorks Device Library
419
MPU6000_I2C_ADDR
Synopsis
#define MPU6000_I2C_ADDR(AD0) (0xD0 + 2*(AD0))
CrossWorks Device Library CrossWorks Device Library
420
MPU6000_t
Synopsis
typedef struct { CTL_IMU_t core; CTL_GYROSCOPE_t gyro; CTL_ACCELEROMETER_t accel; unsigned char __product_id;} MPU6000_t;
Description
MPU6000_t contains the instance data for the MPU-6000 accelerometer and gyroscope sensor group.
Structure
core
The core IMU structure. The IMU structure is initialized with pointers to the gyro, accel, and mag members.
accel
The instance containing the state of the MPU-6000 accelerometer.
gyro
The instance containing the state of the MPU-6000 gyroscope.
__product_id
A private member that contains the value read from the MPU-6000's product ID register.
CrossWorks Device Library CrossWorks Device Library
421
mpu6000_aux_transport_setup
Synopsis
CTL_STATUS_t mpu6000_aux_transport_setup(CTL_TRANSPORT_t *aux, MPU6000_t *mpu);
Description
mpu6000_aux_transport_setup initializes the transport aux to issue I2C transactions on the MPU-60x0 mpu
auxiliary I2C bus. This allows SPI-based MPU-6000s to control a magnetometer, or any other sensor, attached to
its auxiliary I2C bus.
Return Value
mpu6000_aux_transport_setup returns a standard status code.
Thread Safety
mpu6000_aux_transport_setup is thread-safe if the transport aux is thread-safe. Typically, for SPI and I2C
transports, you ensure thread safety by associating a mutex with the bus used by the transport.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
422
mpu6000_initialize_i2c
Synopsis
CTL_STATUS_t mpu6000_initialize_i2c(MPU6000_t *self, CTL_I2C_BUS_t *bus, int addr);
Description
mpu6000_initialize_i2c initializes the MPU-6000's accelerometer and gyroscope on the I2C bus bus using the
8-bit I2C address addr. When complete, the the IMU member core is initialized pointing to the appropriate
members within self with the magnetometer set to zero.
Return Value
mpu6000_initialize_i2c returns a standard status code.
Thread Safety
mpu6000_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
423
mpu6000_initialize_spi
Synopsis
CTL_STATUS_t mpu6000_initialize_spi(MPU6000_t *self, CTL_SPI_DEVICE_t *dev);
Description
mpu6000_initialize_spi initializes the MPU-6000's accelerometer and gyroscope, on the SPI bus associated with
dev. The MPU-6000 device dev is initialized to 8-bit mode 0 at 1 MHz. When complete, the the IMU member core
is initialized pointing to the appropriate members within self with the magnetometer set to zero.
Return Value
mpu6000_initialize_spi returns a standard status code.
Thread Safety
mpu6000_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
424
mpu6000_read_die_temperature
Synopsis
CTL_STATUS_t mpu6000_read_die_temperature(MPU6000_t *self, float *temp);
Description
this reads the die temperature of the MPU-6000 into temp.
Return Value
mpu6000_read_die_temperature returns a standard status code. If the status indicates an error, the returned
sample data is undefined.
Thread Safety
mpu6000_read_die_temperature is thread-safe if the transport member in self is thread-safe. Typically, for SPI
and I2C transports, you ensure thread safety by associating a mutex with the bus used by the transport.
CrossWorks Device Library CrossWorks Device Library
425
mpu6000_revision
Synopsis
char *mpu6000_revision(const MPU6000_t *self);
Description
mpu6000_revision decodes the product ID into a printable string describing the specific device and silicon
revision.
mpu6000_revision returns a string describing the specific device.
CrossWorks Device Library CrossWorks Device Library
426
<sca3000.h>
Overview
Driver for a VTI SCA3000 3-axis accelerometer.
Resources
All correct at time of writing, but as always, manufacturers love to move things around on their website.
Web page
http://www.vti.fi/en/products/accelerometers
Datasheet
http://www.sparkfun.com/datasheets/Sensors/Accelerometer/SCA3000-Manual.pdf
Test hardware
This code has been tested using a SparkFun SCA3000 Breakout:
http://www.sparkfun.com/products/8791
This is plugged into a custom CoreProto rivet and plugged into a SenseCore:
http://soldercore.com/products/sensecore/
And finally installed on a SolderCore:
http://soldercore.com/products/soldercore/
Specification
Device I2C SPI Range
SCA3000-D01 1.6 MHz ±2 g
SCA3000-D02 400 kHz ±2 g
SCA3000-D03 400 kHz 3.2 MHz ±1.1 g
SCA3000-E01 325 kHz ±3 g
SCA3000-E02 100 kHz ±6 g
SCA3000-E04 325 kHz ±18 g
CrossWorks Device Library CrossWorks Device Library
427
SCA3000-L01 100 kHz 1.6 MHz ±4 g
API Summary
Functions
sca3000_initialize_i2c Initialize sensor on I2C bus
sca3000_initialize_spi Initialize sensor on SPI bus
CrossWorks Device Library CrossWorks Device Library
428
sca3000_initialize_i2c
Synopsis
CTL_STATUS_t sca3000_initialize_i2c(CTL_ACCELEROMETER_t *self, CTL_I2C_BUS_t *bus, int addr, SCA3000_DEVICE_t variant);
Description
sca3000_initialize_i2c initializes the accelerometer interface self with methods to communicate with an
SCA3000 accelerometer on the I2C bus bus with 8-bit I2C address addr. The particular SCA3000 device variant is
specified by variant.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
sca3000_initialize_i2c returns a standard status code.
Thread Safety
sca3000_initialize_i2c is thread-safe if a mutex is associated with the I2C bus bus.
See Also
<ctl_sensors.h>
CrossWorks Device Library CrossWorks Device Library
429
sca3000_initialize_spi
Synopsis
CTL_STATUS_t sca3000_initialize_spi(CTL_ACCELEROMETER_t *self, CTL_SPI_DEVICE_t *dev, SCA3000_DEVICE_t variant);
Description
sca3000_initialize_spi initializes the accelerometer interface self with methods to communicate with an
SCA3000 accelerometer on the SPI bus associated with dev. The particular SCA3000 device variant is specified by
variant. The protocol for device dev is set to 1 MHz, 8-bit SPI mode 0.
Once the accelerometer interface is initialized, you can use all standard accelerometer methods from the sensor
API on the interface.
Return Value
sca3000_initialize_spi returns a standard status code.
Thread Safety
sca3000_initialize_spi is thread-safe if a mutex is associated with the SPI bus that dev is attached to.
See Also
<ctl_sensors.h>