This is a complete listing of the RS-EDP software for the mbed module to support the RS-EDP platform.

Dependencies:   mbed

Committer:
DavidGilesHitex
Date:
Fri Nov 19 09:49:16 2010 +0000
Revision:
0:5b7639d1f2c4

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidGilesHitex 0:5b7639d1f2c4 1 /* This module is to drive the Serial Digital I/O PCA9555 Device */
DavidGilesHitex 0:5b7639d1f2c4 2 /* ************************************************************* */
DavidGilesHitex 0:5b7639d1f2c4 3
DavidGilesHitex 0:5b7639d1f2c4 4
DavidGilesHitex 0:5b7639d1f2c4 5 /* Version 1.00 */
DavidGilesHitex 0:5b7639d1f2c4 6 /* Start Date: 23/6/09 */
DavidGilesHitex 0:5b7639d1f2c4 7
DavidGilesHitex 0:5b7639d1f2c4 8
DavidGilesHitex 0:5b7639d1f2c4 9 /* The digital Output from the serial latch drive the ULN2003 line driver devices */
DavidGilesHitex 0:5b7639d1f2c4 10 /* The digital input devices come through a protection circuit on the board and are then fed into the serial input latch */
DavidGilesHitex 0:5b7639d1f2c4 11
DavidGilesHitex 0:5b7639d1f2c4 12
DavidGilesHitex 0:5b7639d1f2c4 13 /* Include Files Here */
DavidGilesHitex 0:5b7639d1f2c4 14 #include "mbed.h" /* mbed header file */
DavidGilesHitex 0:5b7639d1f2c4 15 #include "misra_types.h" /* MISRA Types header file */
DavidGilesHitex 0:5b7639d1f2c4 16 #include "defines.h"
DavidGilesHitex 0:5b7639d1f2c4 17 #include "RSEDP_Slave_Address_Defines.h" /* Slave Address of CNTRL I2C devices */
DavidGilesHitex 0:5b7639d1f2c4 18
DavidGilesHitex 0:5b7639d1f2c4 19 #include "mbed_Port_Structure.h" /* Port structure for MBED Module */
DavidGilesHitex 0:5b7639d1f2c4 20 #include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */
DavidGilesHitex 0:5b7639d1f2c4 21
DavidGilesHitex 0:5b7639d1f2c4 22
DavidGilesHitex 0:5b7639d1f2c4 23
DavidGilesHitex 0:5b7639d1f2c4 24
DavidGilesHitex 0:5b7639d1f2c4 25 /* Function Prototypes Here */
DavidGilesHitex 0:5b7639d1f2c4 26 sint32_t RSEDP_DIO_setup_PCA9555(uint8_t Slave_Address, uint8_t Port0_IO_Direction,uint8_t Port1_IO_Direction); /* Setup the device I/O Direction */
DavidGilesHitex 0:5b7639d1f2c4 27 sint32_t RSEDP_DIO_PCA9555_Write_Word(uint8_t Slave_Address, uint8_t Port0_Payload, uint8_t Port1_Payload); /* Write to the I/O pins */
DavidGilesHitex 0:5b7639d1f2c4 28 sint32_t RSEDP_DIO_PCA9555_Read_Data(uint8_t Slave_Address, uint8_t *Port0_Data, uint8_t*Port1_Data); /* Read data on the input pins */
DavidGilesHitex 0:5b7639d1f2c4 29
DavidGilesHitex 0:5b7639d1f2c4 30 static sint32_t PCA9555_Write_Data(uint8_t Slave_Address, uint8_t command_byte, uint8_t P0_payload, uint8_t P1_payload);/* Local function used to xfer data to the I2C Module */
DavidGilesHitex 0:5b7639d1f2c4 31
DavidGilesHitex 0:5b7639d1f2c4 32
DavidGilesHitex 0:5b7639d1f2c4 33
DavidGilesHitex 0:5b7639d1f2c4 34 /* Setup the device I/O Direction of the Latch*/
DavidGilesHitex 0:5b7639d1f2c4 35 sint32_t RSEDP_DIO_setup_PCA9555(uint8_t Slave_Address, uint8_t Port0_IO_Direction,uint8_t Port1_IO_Direction)
DavidGilesHitex 0:5b7639d1f2c4 36 {
DavidGilesHitex 0:5b7639d1f2c4 37 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 38 /* Assume the I2C peripheral and I/O is already configured */
DavidGilesHitex 0:5b7639d1f2c4 39
DavidGilesHitex 0:5b7639d1f2c4 40 Ack_Status = PCA9555_Write_Data(Slave_Address, 0x06, Port0_IO_Direction, Port1_IO_Direction); /* This 0x06 = configures the I/O direction */
DavidGilesHitex 0:5b7639d1f2c4 41 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 42 }
DavidGilesHitex 0:5b7639d1f2c4 43
DavidGilesHitex 0:5b7639d1f2c4 44
DavidGilesHitex 0:5b7639d1f2c4 45
DavidGilesHitex 0:5b7639d1f2c4 46 /* Write Data Out to the Port Latches */
DavidGilesHitex 0:5b7639d1f2c4 47 sint32_t RSEDP_DIO_PCA9555_Write_Word(uint8_t Slave_Address, uint8_t Port0_Payload, uint8_t Port1_Payload)
DavidGilesHitex 0:5b7639d1f2c4 48 {
DavidGilesHitex 0:5b7639d1f2c4 49 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 50
DavidGilesHitex 0:5b7639d1f2c4 51 Ack_Status = PCA9555_Write_Data(Slave_Address, 0x02, Port0_Payload, Port1_Payload); /* This Writes the data to the I/O latches */
DavidGilesHitex 0:5b7639d1f2c4 52 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 53 }
DavidGilesHitex 0:5b7639d1f2c4 54
DavidGilesHitex 0:5b7639d1f2c4 55
DavidGilesHitex 0:5b7639d1f2c4 56 /* Read the values on the serial latch pins */
DavidGilesHitex 0:5b7639d1f2c4 57 sint32_t RSEDP_DIO_PCA9555_Read_Data(uint8_t Slave_Address, uint8_t *Port0_Data, uint8_t*Port1_Data)
DavidGilesHitex 0:5b7639d1f2c4 58 {
DavidGilesHitex 0:5b7639d1f2c4 59 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 60 sint8_t rx_array[2] = {0x00, 0x00}; /* Local reception array */
DavidGilesHitex 0:5b7639d1f2c4 61 sint8_t tx_array[1] = {0x000}; /* Data to transmit */
DavidGilesHitex 0:5b7639d1f2c4 62
DavidGilesHitex 0:5b7639d1f2c4 63 tx_array[0] = 0; /* Command Byte For Read */
DavidGilesHitex 0:5b7639d1f2c4 64
DavidGilesHitex 0:5b7639d1f2c4 65 Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1);
DavidGilesHitex 0:5b7639d1f2c4 66
DavidGilesHitex 0:5b7639d1f2c4 67 if (Ack_Status == ACK)
DavidGilesHitex 0:5b7639d1f2c4 68 {
DavidGilesHitex 0:5b7639d1f2c4 69 Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, rx_array, 2); /* Receive two bytes from the serial latch */
DavidGilesHitex 0:5b7639d1f2c4 70 *Port0_Data = rx_array[0]; /* Transfer Port 0 Data to pointer */
DavidGilesHitex 0:5b7639d1f2c4 71 *Port1_Data = rx_array[1]; /* Transfer Port 1 Data to pointer */
DavidGilesHitex 0:5b7639d1f2c4 72 }
DavidGilesHitex 0:5b7639d1f2c4 73 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 74 }
DavidGilesHitex 0:5b7639d1f2c4 75
DavidGilesHitex 0:5b7639d1f2c4 76
DavidGilesHitex 0:5b7639d1f2c4 77
DavidGilesHitex 0:5b7639d1f2c4 78
DavidGilesHitex 0:5b7639d1f2c4 79
DavidGilesHitex 0:5b7639d1f2c4 80 /* Write address, command byte plus two additional bytes of data to the device */
DavidGilesHitex 0:5b7639d1f2c4 81 static sint32_t PCA9555_Write_Data(uint8_t Slave_Address, uint8_t command_byte, uint8_t P0_payload, uint8_t P1_payload)
DavidGilesHitex 0:5b7639d1f2c4 82 {
DavidGilesHitex 0:5b7639d1f2c4 83 sint32_t Ack_Status = 0;
DavidGilesHitex 0:5b7639d1f2c4 84 sint8_t tx_array[3]; /* Local array of data to be transmitted */
DavidGilesHitex 0:5b7639d1f2c4 85
DavidGilesHitex 0:5b7639d1f2c4 86 tx_array[0] = command_byte; /* Load transmit array */
DavidGilesHitex 0:5b7639d1f2c4 87 tx_array[1] = P0_payload; /* First is for Port 0 */
DavidGilesHitex 0:5b7639d1f2c4 88 tx_array[2] = P1_payload; /* Second is for Port 1 */
DavidGilesHitex 0:5b7639d1f2c4 89
DavidGilesHitex 0:5b7639d1f2c4 90 Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 3); /* Send 3 bytes */
DavidGilesHitex 0:5b7639d1f2c4 91 return Ack_Status;
DavidGilesHitex 0:5b7639d1f2c4 92 }
DavidGilesHitex 0:5b7639d1f2c4 93