Manuel Caballero / PCF8574
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCF8574.cpp Source File

PCF8574.cpp

00001 /**
00002  * @brief       PCF8574.h
00003  * @details     Remote 8-bit I/O expander for I2C-bus with interrupt.
00004  *              Functions file.
00005  *
00006  *
00007  * @return      NA
00008  *
00009  * @author      Manuel Caballero
00010  * @date        11/October/2017
00011  * @version     11/October/2017    The ORIGIN
00012  * @pre         NaN.
00013  * @warning     NaN
00014  * @pre         This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
00015  */
00016 
00017 #include "PCF8574.h"
00018 
00019 
00020 PCF8574::PCF8574 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq )
00021     : i2c          ( sda, scl )
00022     , PCF8574_Addr ( addr )
00023 {
00024     i2c.frequency( freq );
00025 }
00026 
00027 
00028 PCF8574::~PCF8574()
00029 {
00030 }
00031 
00032 
00033 
00034 /**
00035  * @brief       PCF8574_SetPins ( PCF8574_vector_data_t )
00036  *
00037  * @details     It configures/sets the pins of the device.
00038  *
00039  * @param[in]    myConfDATA:        Data to set up the device.
00040  *
00041  * @param[out]   NaN.
00042  *
00043  *
00044  * @return       Status of PCF8574_SetPins.
00045  *
00046  *
00047  * @author      Manuel Caballero
00048  * @date        11/October/2017
00049  * @version     11/October/2017   The ORIGIN
00050  * @pre         NaN
00051  * @warning     NaN.
00052  */
00053 PCF8574::PCF8574_status_t  PCF8574::PCF8574_SetPins ( PCF8574_vector_data_t  myConfDATA )
00054 {
00055     uint32_t    aux                 =    0;
00056 
00057 
00058     aux = i2c.write ( PCF8574_Addr, &myConfDATA.data, 1 );
00059 
00060 
00061 
00062     if ( aux == I2C_SUCCESS  )
00063        return   PCF8574_SUCCESS;
00064     else
00065        return   PCF8574_FAILURE;
00066 }
00067 
00068 
00069 
00070 /**
00071  * @brief       PCF8574_ReadPins ( PCF8574_vector_data_t*  )
00072  *
00073  * @details     It gets the data from the device ( port status ).
00074  *
00075  * @param[in]    NaN.
00076  *
00077  * @param[out]   myReadDATA:        ADC result into the chosen channel.
00078  *
00079  *
00080  * @return       Status of PCF8574_ReadPins.
00081  *
00082  *
00083  * @author      Manuel Caballero
00084  * @date        11/October/2017
00085  * @version     11/October/2017   The ORIGIN
00086  * @pre         NaN
00087  * @warning     NaN.
00088  */
00089 PCF8574::PCF8574_status_t  PCF8574::PCF8574_ReadPins ( PCF8574_vector_data_t* myReadDATA )
00090 {
00091     uint32_t    aux                 =    0;
00092 
00093 
00094     aux = i2c.read ( PCF8574_Addr, &myReadDATA->data, 1 );
00095 
00096 
00097 
00098     if ( aux == I2C_SUCCESS  )
00099        return   PCF8574_SUCCESS;
00100     else
00101        return   PCF8574_FAILURE;
00102 }