DHCOM_HAL
Hardware-abstraction library (HAL) for multiple targets, including DHCOM modules
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions
dhcom::I2CBus Class Reference

Represents an I2C bus of a DHCOM Module. Not available on PC. More...

#include <I2CBus.h>

Public Types

enum  BUS { BUS_I2C1 = 1, BUS_I2C2 = 2, BUS_I2C3 = 3 }
 Master device enumeration. More...
 

Public Member Functions

 I2CBus (BUS bus)
 Constructs the I2CBus object.
 
 ~I2CBus ()
 Destroys the I2CBus object and releases the resources.
 
STATUS open ()
 Opens the bus, claims the hardware resources.
 
STATUS close ()
 Closes the bus, releases resources.
 
bool isOpen () const
 Checks if the bus is open and ready for I/O.
 
STATUS selectSlave (uint16_t address)
 Selects an I2C slave to communicate with.
 
STATUS read (uint8_t *buffer, uint32_t count) const
 Reads a block of bytes from a slave.
 
uint8_t read (STATUS *status=NULL) const
 Reads one byte from a slave.
 
STATUS write (const uint8_t *buffer, uint32_t count)
 Writes a block of bytes to the slave.
 
STATUS write (uint8_t byte)
 Writes one byte to the I2C slave.
 

Detailed Description

Represents an I2C bus of a DHCOM Module. Not available on PC.

Member Enumeration Documentation

Master device enumeration.

Enumerator:
BUS_I2C1 

I2C master device 1.

BUS_I2C2 

I2C master device 2.

BUS_I2C3 

I2C master device 3.

Constructor & Destructor Documentation

dhcom::I2CBus::I2CBus ( BUS  bus)

Constructs the I2CBus object.

Parameters
bus- the physical I2C bus to open later.
dhcom::I2CBus::~I2CBus ( )

Destroys the I2CBus object and releases the resources.

This call also closes the bus if necessary.

Member Function Documentation

STATUS dhcom::I2CBus::close ( )

Closes the bus, releases resources.

Returns
- always STATUS_SUCCESS.
bool dhcom::I2CBus::isOpen ( ) const

Checks if the bus is open and ready for I/O.

Returns
true if the bus is open.
STATUS dhcom::I2CBus::open ( )

Opens the bus, claims the hardware resources.

Returns
- may return STATUS_DEVICE_ALREADY_OPEN, STATUS_DEVICE_OPEN_FAILED or STATUS_SUCCESS.
STATUS dhcom::I2CBus::read ( uint8_t buffer,
uint32_t  count 
) const

Reads a block of bytes from a slave.

Parameters
buffer- the pointer to receiving buffer, may not be NULL;
count- the number of bytes to receive;
Returns
- may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_READ_FAILED or STATUS_SUCCESS.
uint8_t dhcom::I2CBus::read ( STATUS status = NULL) const

Reads one byte from a slave.

Parameters
status- if NULL - no status returned, otherwise the status is assigned to STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_READ_FAILED or STATUS_SUCCESS.
Returns
- the value received.
STATUS dhcom::I2CBus::selectSlave ( uint16_t  address)

Selects an I2C slave to communicate with.

Parameters
address- the slave address.
Returns
- may return STATUS_DEVICE_NOT_OPEN, STATUS_I2C_SLAVE_SELECT_FAILED or STATUS_SUCCESS.
STATUS dhcom::I2CBus::write ( const uint8_t buffer,
uint32_t  count 
)

Writes a block of bytes to the slave.

Parameters
buffer- the pointer to buffer with the data, may not be NULL;
count- the number of bytes to send;
Returns
- may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_WRITE_FAILED or STATUS_SUCCESS.
STATUS dhcom::I2CBus::write ( uint8_t  byte)

Writes one byte to the I2C slave.

Parameters
byte- the value to write.
Returns
- may return STATUS_DEVICE_NOT_OPEN, STATUS_DEVICE_WRITE_FAILED or STATUS_SUCCESS.

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