Using the Library

This section explains the functions available to the user by this library. The prototypes remain the same irrespective of the Atmel AVR and interface used. For this purpose, this section assumes that the file “atmel_led_device_config.h” is correctly configured.

The library provides the following application programmer interfaces (APIs). More information on these can be found in the accompanying Doxygen documentation.

atmel_led_drvr_init()

This function configures the AVR to act as a master. Call this function before further communication with the slave. This function returns void.

atmel_led_drvr_writeregister(slave_address, REG_ADDR. REG_DATA)

This function accesses the MSLxxxx slave at slave_address and writes REG_DATA to its internal register at REG_ADDR. The function returns 1 if successful, else it returns 0.

atmel_led_drvr_readregister(slave_address, REG_ADDR, *receivedData)

This function accesses the slave at slave_address and reads its internal register at REG_ADDR and stores the data in receivedData pointer. The function returns 1 if successful, else it returns 0.

atmel_led_drvr_writearray(slave_address, REG_ADDR, *Data, count)

This function writes a byte array of length ‘count’ pointed by ‘Data’ pointer to a slave at slave_address, starting at register address REG_ADDR. For XMEGA and megaAVR devices, this count cannot exceed the NUM_BYTES defined in the configuration file.

atmel_led_drvr_readarray(slave_address, REG_ADDR, *Data, count)

This function reads a byte array of length ‘count’ from a slave at slave_address, starting at register address REG_ADDR into a buffer pointed by ‘Data’ pointer. For XMEGA and megaAVR devices, this count can not exceed the NUM_BYTES defined in the configuration file.

Writing user defined functions

Using the three primitive functions allows writing more user friendly functions which read to and write from to specific registers of LED drivers. For example, the global intensity register of Atmel MSL2160 has an internal address of 0x1F. This register sets global LED intensity. The values 0 to 0xFF correspond to 0 to 100% brightness respectively. The example code below shows a simple wrapper function to set global intensity of a particular slave:

char SetBrighntessLevel(char slave_addr, char intensity)
{
    return atmel_led_drvr_writeregister(slave_addr, 0x1F,
                                        intensity);
}