David Giles
/
CM-MBED_RSEDP_Test_Suite_LPC1768_V3
This is a complete listing of the RS-EDP software for the mbed module to support the RS-EDP platform.
SourceFiles/RSEDP_BB_PCA9675_Serial_Input_Latch.cpp@0:5b7639d1f2c4, 2010-11-19 (annotated)
- Committer:
- DavidGilesHitex
- Date:
- Fri Nov 19 09:49:16 2010 +0000
- Revision:
- 0:5b7639d1f2c4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidGilesHitex | 0:5b7639d1f2c4 | 1 | /* Software Driver for Serial Input Latch PCA9675 on the RS-EDP Base Board */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 2 | /* *********************************************************************** */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 3 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 4 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 5 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 6 | /* Version 1.00 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 7 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 8 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 9 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 10 | /* Include Files */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 11 | /* Include Files Here */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 12 | #include "mbed.h" /* mbed header file */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 13 | #include "misra_types.h" /* MISRA Types header file */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 14 | #include "defines.h" |
DavidGilesHitex | 0:5b7639d1f2c4 | 15 | #include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 16 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 17 | #include "mbed_Port_Structure.h" /* Port structure for MBED Module */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 18 | #include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 19 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 20 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 21 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 22 | /* Function Prototypes Defines Here */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 23 | sint32_t RSEDP_BB_setup_PCA9675(uint8_t Slave_Address); /* Setup and configure the I/O latch */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 24 | sint32_t RSEDP_BB_PCA9675_reset(uint8_t Slave_Address); /* Reset the device using a general call */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 25 | sint32_t RSEDP_BB_PCA9675_write_data(uint8_t Slave_Address, uint8_t port0_payload,uint8_t port1_payload); /* Write two bytes of data to the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 26 | sint32_t RSEDP_BB_PCA9675_read_data(uint8_t Slave_Address, uint8_t *read_port0, uint8_t *read_port1); /* Read two bytes from the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 27 | sint32_t RS_EDP_BB_Read_DIP_Switch(uint8_t Switch_Number); /* Read the switch position - either on or off */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 28 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 29 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 30 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 31 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 32 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 33 | /* Configure the Serial I/O Expander IC */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 34 | sint32_t RSEDP_BB_setup_PCA9675(uint8_t Slave_Address) |
DavidGilesHitex | 0:5b7639d1f2c4 | 35 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 36 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 37 | /* Assume the I2C peripheral and MCU I/O is already configured */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 38 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 39 | Ack_Status = RSEDP_BB_PCA9675_reset(Slave_Address); /* Reset the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 40 | if (Ack_Status == ACK) |
DavidGilesHitex | 0:5b7639d1f2c4 | 41 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 42 | Ack_Status = RSEDP_BB_PCA9675_write_data(Slave_Address, 0xff,0xff); /* This configures all I/O as input */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 43 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 44 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 45 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 46 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 47 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 48 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 49 | /* Reset the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 50 | sint32_t RSEDP_BB_PCA9675_reset(uint8_t Slave_Address) |
DavidGilesHitex | 0:5b7639d1f2c4 | 51 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 52 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 53 | sint8_t reset_command = 0x06; /* Reset command following a general call, address 0 will reset the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 54 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 55 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(0x0, &reset_command, 2); /* Send a general call command, (Slave address 0), plus one byte of value 0x06 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 56 | /* The PCA9675 does not generate an ACK on a general call */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 57 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 58 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 59 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 60 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 61 | /* Write two byte of data to the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 62 | sint32_t RSEDP_BB_PCA9675_write_data(uint8_t Slave_Address, uint8_t port0_payload, uint8_t port1_payload) |
DavidGilesHitex | 0:5b7639d1f2c4 | 63 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 64 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 65 | sint8_t tx_array[2]; /* Local array of data to be transmitted */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 66 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 67 | tx_array[0] = port0_payload; /* First is for Port 0 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 68 | tx_array[1] = port1_payload; /* Second is for Port 1 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 69 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 70 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 2); /* Send two bytes plus the slave address to the slave */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 71 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 72 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 73 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 74 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 75 | /* Read two bytes from the device */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 76 | sint32_t RSEDP_BB_PCA9675_read_data(uint8_t Slave_Address, uint8_t *read_port0, uint8_t *read_port1) |
DavidGilesHitex | 0:5b7639d1f2c4 | 77 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 78 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 79 | sint8_t rx_array[2]; /* Local reception array */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 80 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 81 | Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, rx_array, 2); /* Receive two bytes */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 82 | *read_port0=rx_array[0]; /* transfer data back to pointer */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 83 | *read_port1=rx_array[1]; /* transfer data back to pointer */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 84 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 85 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 86 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 87 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 88 | /* Read the switch position - either on or off */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 89 | sint32_t RS_EDP_BB_Read_DIP_Switch(uint8_t Switch_Number, uint8_t *Switch_Status) |
DavidGilesHitex | 0:5b7639d1f2c4 | 90 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 91 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 92 | uint8_t port0 = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 93 | uint8_t port1 = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 94 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 95 | Ack_Status = RSEDP_BB_PCA9675_read_data(PCA9675_BASE_BOARD, &port0, &port1); |
DavidGilesHitex | 0:5b7639d1f2c4 | 96 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 97 | switch (Switch_Number) |
DavidGilesHitex | 0:5b7639d1f2c4 | 98 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 99 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 100 | case 1: |
DavidGilesHitex | 0:5b7639d1f2c4 | 101 | if ((port0 & 0x01) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 102 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 103 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 104 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 105 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 106 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 107 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 108 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 109 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 110 | case 2: |
DavidGilesHitex | 0:5b7639d1f2c4 | 111 | if ((port0 & 0x02) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 112 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 113 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 114 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 115 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 116 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 117 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 118 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 119 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 120 | case 3: |
DavidGilesHitex | 0:5b7639d1f2c4 | 121 | if ((port0 & 0x04) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 122 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 123 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 124 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 125 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 126 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 127 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 128 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 129 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 130 | case 4: |
DavidGilesHitex | 0:5b7639d1f2c4 | 131 | if ((port0 & 0x08) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 132 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 133 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 134 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 135 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 136 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 137 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 138 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 139 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 140 | case 5: |
DavidGilesHitex | 0:5b7639d1f2c4 | 141 | if ((port0 & 0x10) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 142 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 143 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 144 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 145 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 146 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 147 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 148 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 149 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 150 | case 6: |
DavidGilesHitex | 0:5b7639d1f2c4 | 151 | if ((port0 & 0x20) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 152 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 153 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 154 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 155 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 156 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 157 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 158 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 159 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 160 | case 7: |
DavidGilesHitex | 0:5b7639d1f2c4 | 161 | if ((port0 & 0x40) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 162 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 163 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 164 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 165 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 166 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 167 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 168 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 169 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 170 | case 8: |
DavidGilesHitex | 0:5b7639d1f2c4 | 171 | if ((port0 & 0x80) == SWITCH_ON) |
DavidGilesHitex | 0:5b7639d1f2c4 | 172 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 173 | *Switch_Status = DIP_SWITCH_CLOSED; |
DavidGilesHitex | 0:5b7639d1f2c4 | 174 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 175 | else{ |
DavidGilesHitex | 0:5b7639d1f2c4 | 176 | *Switch_Status = DIP_SWITCH_OPEN; |
DavidGilesHitex | 0:5b7639d1f2c4 | 177 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 178 | break; |
DavidGilesHitex | 0:5b7639d1f2c4 | 179 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 180 | default: |
DavidGilesHitex | 0:5b7639d1f2c4 | 181 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 182 | *Switch_Status = port0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 183 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 184 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 185 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 186 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 187 |