class pah8011 for mbed

Committer:
bell_huang
Date:
Wed Jan 23 08:01:57 2019 +0000
Revision:
6:d196b612b14a
Parent:
0:242cf8f28bf2
Remove mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bell_huang 0:242cf8f28bf2 1 /*==============================================================================
bell_huang 0:242cf8f28bf2 2 * Edit History
bell_huang 0:242cf8f28bf2 3 *
bell_huang 0:242cf8f28bf2 4 * This section contains comments describing changes made to the module. Notice
bell_huang 0:242cf8f28bf2 5 * that changes are listed in reverse chronological order. Please use ISO format
bell_huang 0:242cf8f28bf2 6 * for dates.
bell_huang 0:242cf8f28bf2 7 *
bell_huang 0:242cf8f28bf2 8 * when who what, where, why
bell_huang 0:242cf8f28bf2 9 * ---------- --- -----------------------------------------------------------
bell_huang 0:242cf8f28bf2 10 * 2016-10-20 bh - Initial revision.
bell_huang 0:242cf8f28bf2 11 ==============================================================================*/
bell_huang 0:242cf8f28bf2 12
bell_huang 0:242cf8f28bf2 13 #include "pah_8011_internal.h"
bell_huang 0:242cf8f28bf2 14
bell_huang 0:242cf8f28bf2 15 // pah
bell_huang 0:242cf8f28bf2 16 #include "pah_comm.h"
bell_huang 0:242cf8f28bf2 17
bell_huang 0:242cf8f28bf2 18 // platform support
bell_huang 0:242cf8f28bf2 19 #include "pah_platform_functions.h"
bell_huang 0:242cf8f28bf2 20
bell_huang 0:242cf8f28bf2 21
bell_huang 0:242cf8f28bf2 22 //============================================================================
bell_huang 0:242cf8f28bf2 23 // PUBLIC FUNCTION DEFINITIONS
bell_huang 0:242cf8f28bf2 24 //============================================================================
bell_huang 0:242cf8f28bf2 25 pah_ret pah_8011_verify_product_id(void)
bell_huang 0:242cf8f28bf2 26 {
bell_huang 0:242cf8f28bf2 27 pah_ret ret = pah_err_unknown;
bell_huang 0:242cf8f28bf2 28 uint8_t data = 0;
bell_huang 0:242cf8f28bf2 29
bell_huang 0:242cf8f28bf2 30 if (!pah_comm_write(0x7F, 0x00)) //bank0
bell_huang 0:242cf8f28bf2 31 {
bell_huang 0:242cf8f28bf2 32 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 33 goto FAIL;
bell_huang 0:242cf8f28bf2 34 }
bell_huang 0:242cf8f28bf2 35 if (!pah_comm_read(0x00, &data))
bell_huang 0:242cf8f28bf2 36 {
bell_huang 0:242cf8f28bf2 37 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 38 goto FAIL;
bell_huang 0:242cf8f28bf2 39 }
bell_huang 0:242cf8f28bf2 40
bell_huang 0:242cf8f28bf2 41 if (data != PAH_PRODUCT_ID)
bell_huang 0:242cf8f28bf2 42 {
bell_huang 0:242cf8f28bf2 43 debug_printf_1("pah_8011_verify_product_id() fail. id = 0x%X \n", data);
bell_huang 0:242cf8f28bf2 44 ret = pah_err_verify_device_fail;
bell_huang 0:242cf8f28bf2 45 goto FAIL;
bell_huang 0:242cf8f28bf2 46 }
bell_huang 0:242cf8f28bf2 47
bell_huang 0:242cf8f28bf2 48 debug_printf_1("pah_8011_verify_product_id() success. id = 0x%X \n", data);
bell_huang 0:242cf8f28bf2 49
bell_huang 0:242cf8f28bf2 50 return pah_success;
bell_huang 0:242cf8f28bf2 51
bell_huang 0:242cf8f28bf2 52 FAIL:
bell_huang 0:242cf8f28bf2 53 debug_printf_1("pah8011_verify_product_id() failed. ret = %d \n", ret);
bell_huang 0:242cf8f28bf2 54 return ret;
bell_huang 0:242cf8f28bf2 55 }
bell_huang 0:242cf8f28bf2 56
bell_huang 0:242cf8f28bf2 57 pah_ret pah_8011_write_touch_package_setting(void)
bell_huang 0:242cf8f28bf2 58 {
bell_huang 0:242cf8f28bf2 59 pah_ret ret = pah_err_unknown;
bell_huang 0:242cf8f28bf2 60 device_package_e device_package;
bell_huang 0:242cf8f28bf2 61
bell_huang 0:242cf8f28bf2 62 ret = pah_8011_read_device_package(&device_package);
bell_huang 0:242cf8f28bf2 63 if (PAH_FAILED(ret))
bell_huang 0:242cf8f28bf2 64 goto FAIL;
bell_huang 0:242cf8f28bf2 65
bell_huang 0:242cf8f28bf2 66 switch (device_package)
bell_huang 0:242cf8f28bf2 67 {
bell_huang 0:242cf8f28bf2 68 case device_package_et:
bell_huang 0:242cf8f28bf2 69 {
bell_huang 0:242cf8f28bf2 70 if (!pah_comm_write(0x7F, 0x01)) //bank1
bell_huang 0:242cf8f28bf2 71 {
bell_huang 0:242cf8f28bf2 72 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 73 goto FAIL;
bell_huang 0:242cf8f28bf2 74 }
bell_huang 0:242cf8f28bf2 75 if (!pah_comm_write(0x05, 0x04)) // Cmd_TouchDetection_Th_Hi_15_8
bell_huang 0:242cf8f28bf2 76 {
bell_huang 0:242cf8f28bf2 77 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 78 goto FAIL;
bell_huang 0:242cf8f28bf2 79 }
bell_huang 0:242cf8f28bf2 80 if (!pah_comm_write(0x08, 0x04)) // Cmd_TouchDetection_Th_Lo_15_8
bell_huang 0:242cf8f28bf2 81 {
bell_huang 0:242cf8f28bf2 82 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 83 goto FAIL;
bell_huang 0:242cf8f28bf2 84 }
bell_huang 0:242cf8f28bf2 85 if (!pah_comm_write(0x14, 0x06)) // Cmd_adc_osr_t
bell_huang 0:242cf8f28bf2 86 {
bell_huang 0:242cf8f28bf2 87 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 88 goto FAIL;
bell_huang 0:242cf8f28bf2 89 }
bell_huang 0:242cf8f28bf2 90 if (!pah_comm_write(0x75, 0x00)) // T_ledbias_sel
bell_huang 0:242cf8f28bf2 91 {
bell_huang 0:242cf8f28bf2 92 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 93 goto FAIL;
bell_huang 0:242cf8f28bf2 94 }
bell_huang 0:242cf8f28bf2 95 }
bell_huang 0:242cf8f28bf2 96 break;
bell_huang 0:242cf8f28bf2 97
bell_huang 0:242cf8f28bf2 98 case device_package_es:
bell_huang 0:242cf8f28bf2 99 //// No need to modify, because these values are default or defined in init settings.
bell_huang 0:242cf8f28bf2 100 // switch to bank1
bell_huang 0:242cf8f28bf2 101 //Cmd_TouchDetection_Th_Hi_15_8 = 0x07;
bell_huang 0:242cf8f28bf2 102 //Cmd_TouchDetection_Th_Lo_15_8 = 0x06;
bell_huang 0:242cf8f28bf2 103 //Cmd_adc_osr_t = 0x03;
bell_huang 0:242cf8f28bf2 104 //T_ledbias_sel = 0x03;
bell_huang 0:242cf8f28bf2 105 break;
bell_huang 0:242cf8f28bf2 106
bell_huang 0:242cf8f28bf2 107 default:
bell_huang 0:242cf8f28bf2 108 ret = pah_err_not_implement;
bell_huang 0:242cf8f28bf2 109 goto FAIL;
bell_huang 0:242cf8f28bf2 110 }
bell_huang 0:242cf8f28bf2 111
bell_huang 0:242cf8f28bf2 112 return pah_success;
bell_huang 0:242cf8f28bf2 113
bell_huang 0:242cf8f28bf2 114 FAIL:
bell_huang 0:242cf8f28bf2 115 debug_printf_1("pah_8011_set_touch_setting() failed. ret = %d \n", ret);
bell_huang 0:242cf8f28bf2 116 return ret;
bell_huang 0:242cf8f28bf2 117 }
bell_huang 0:242cf8f28bf2 118
bell_huang 0:242cf8f28bf2 119 pah_ret pah_8011_write_reg_array(const uint8_t reg_array[][2], uint32_t length)
bell_huang 0:242cf8f28bf2 120 {
bell_huang 0:242cf8f28bf2 121 uint32_t i = 0;
bell_huang 0:242cf8f28bf2 122
bell_huang 0:242cf8f28bf2 123 for (i = 0; i < length; ++i)
bell_huang 0:242cf8f28bf2 124 {
bell_huang 0:242cf8f28bf2 125 if (!pah_comm_write(reg_array[i][0], reg_array[i][1]))
bell_huang 0:242cf8f28bf2 126 {
bell_huang 0:242cf8f28bf2 127 debug_printf_1("pah_8011_write_reg_array(). pah_comm_write fail, i = %d \n", i);
bell_huang 0:242cf8f28bf2 128 return pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 129 }
bell_huang 0:242cf8f28bf2 130 }
bell_huang 0:242cf8f28bf2 131
bell_huang 0:242cf8f28bf2 132 return pah_success;
bell_huang 0:242cf8f28bf2 133 }
bell_huang 0:242cf8f28bf2 134
bell_huang 0:242cf8f28bf2 135 pah_ret pah_8011_update_flag(void)
bell_huang 0:242cf8f28bf2 136 {
bell_huang 0:242cf8f28bf2 137 if (!pah_comm_write(0x7F, 0x01)) //bank1
bell_huang 0:242cf8f28bf2 138 return pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 139 if (!pah_comm_write(0x24, 0x01))
bell_huang 0:242cf8f28bf2 140 return pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 141
bell_huang 0:242cf8f28bf2 142 return pah_success;
bell_huang 0:242cf8f28bf2 143 }
bell_huang 0:242cf8f28bf2 144
bell_huang 0:242cf8f28bf2 145 pah_ret pah_8011_device_init(void)
bell_huang 0:242cf8f28bf2 146 {
bell_huang 0:242cf8f28bf2 147 pah_ret ret = pah_err_unknown;
bell_huang 0:242cf8f28bf2 148
bell_huang 0:242cf8f28bf2 149 if (!pah_comm_write(0x7F, 0x04)) //bank4
bell_huang 0:242cf8f28bf2 150 {
bell_huang 0:242cf8f28bf2 151 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 152 goto FAIL;
bell_huang 0:242cf8f28bf2 153 }
bell_huang 0:242cf8f28bf2 154 if (!pah_comm_write(0x15, 0x69)) // set int pins as output mode
bell_huang 0:242cf8f28bf2 155 {
bell_huang 0:242cf8f28bf2 156 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 157 goto FAIL;
bell_huang 0:242cf8f28bf2 158 }
bell_huang 0:242cf8f28bf2 159 if (!pah_comm_write(0x34, 0x01)) // disable power on reset
bell_huang 0:242cf8f28bf2 160 {
bell_huang 0:242cf8f28bf2 161 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 162 goto FAIL;
bell_huang 0:242cf8f28bf2 163 }
bell_huang 0:242cf8f28bf2 164
bell_huang 0:242cf8f28bf2 165 // set int pins floating
bell_huang 0:242cf8f28bf2 166 if (pah_comm_bus_spi == pah_comm_get_bus_type())
bell_huang 0:242cf8f28bf2 167 {
bell_huang 0:242cf8f28bf2 168 if (!pah_comm_write(0x2B, 0xFF))
bell_huang 0:242cf8f28bf2 169 {
bell_huang 0:242cf8f28bf2 170 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 171 goto FAIL;
bell_huang 0:242cf8f28bf2 172 }
bell_huang 0:242cf8f28bf2 173 if (!pah_comm_write(0x70, 0x08))
bell_huang 0:242cf8f28bf2 174 {
bell_huang 0:242cf8f28bf2 175 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 176 goto FAIL;
bell_huang 0:242cf8f28bf2 177 }
bell_huang 0:242cf8f28bf2 178 }
bell_huang 0:242cf8f28bf2 179 else // i2c
bell_huang 0:242cf8f28bf2 180 {
bell_huang 0:242cf8f28bf2 181 if (!pah_comm_write(0x2B, 0xFE))
bell_huang 0:242cf8f28bf2 182 {
bell_huang 0:242cf8f28bf2 183 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 184 goto FAIL;
bell_huang 0:242cf8f28bf2 185 }
bell_huang 0:242cf8f28bf2 186 if (!pah_comm_write(0x70, 0x18))
bell_huang 0:242cf8f28bf2 187 {
bell_huang 0:242cf8f28bf2 188 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 189 goto FAIL;
bell_huang 0:242cf8f28bf2 190 }
bell_huang 0:242cf8f28bf2 191 }
bell_huang 0:242cf8f28bf2 192
bell_huang 0:242cf8f28bf2 193 return pah_success;
bell_huang 0:242cf8f28bf2 194
bell_huang 0:242cf8f28bf2 195 FAIL:
bell_huang 0:242cf8f28bf2 196 debug_printf_1("pah_8011_write_init_setting() failed. ret = %d \n", ret);
bell_huang 0:242cf8f28bf2 197 return ret;
bell_huang 0:242cf8f28bf2 198 }
bell_huang 0:242cf8f28bf2 199
bell_huang 0:242cf8f28bf2 200 pah_ret pah_8011_startup(void)
bell_huang 0:242cf8f28bf2 201 {
bell_huang 0:242cf8f28bf2 202 if (!pah_comm_write(0x7F, 0x04)) //bank4
bell_huang 0:242cf8f28bf2 203 return pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 204 if (!pah_comm_write(0x69, 0x00))
bell_huang 0:242cf8f28bf2 205 return pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 206
bell_huang 0:242cf8f28bf2 207 // When the device wakes up from power down mode, delay is necessary for the internal controller to reset the whole system and then the device is ready for the upcoming operations.
bell_huang 0:242cf8f28bf2 208 // Without delay, the driver would be unable to write settings correctly.
bell_huang 0:242cf8f28bf2 209 delay_ms(2);
bell_huang 0:242cf8f28bf2 210
bell_huang 0:242cf8f28bf2 211 return pah_success;
bell_huang 0:242cf8f28bf2 212 }
bell_huang 0:242cf8f28bf2 213
bell_huang 0:242cf8f28bf2 214 pah_ret pah_8011_shutdown(pah_powerdown_int_status_e powerdown_int_status)
bell_huang 0:242cf8f28bf2 215 {
bell_huang 0:242cf8f28bf2 216 pah_ret ret = pah_err_unknown;
bell_huang 0:242cf8f28bf2 217
bell_huang 0:242cf8f28bf2 218 if (!pah_comm_write(0x7F, 0x04)) //bank4
bell_huang 0:242cf8f28bf2 219 {
bell_huang 0:242cf8f28bf2 220 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 221 goto FAIL;
bell_huang 0:242cf8f28bf2 222 }
bell_huang 0:242cf8f28bf2 223
bell_huang 0:242cf8f28bf2 224 if (pah_powerdown_int_status_down == powerdown_int_status)
bell_huang 0:242cf8f28bf2 225 {
bell_huang 0:242cf8f28bf2 226 // set int pins pull down
bell_huang 0:242cf8f28bf2 227 if (pah_comm_bus_spi == pah_comm_get_bus_type())
bell_huang 0:242cf8f28bf2 228 {
bell_huang 0:242cf8f28bf2 229 if (!pah_comm_write(0x2B, 0xF9))
bell_huang 0:242cf8f28bf2 230 {
bell_huang 0:242cf8f28bf2 231 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 232 goto FAIL;
bell_huang 0:242cf8f28bf2 233 }
bell_huang 0:242cf8f28bf2 234 }
bell_huang 0:242cf8f28bf2 235 else // i2c
bell_huang 0:242cf8f28bf2 236 {
bell_huang 0:242cf8f28bf2 237 if (!pah_comm_write(0x2B, 0xF8))
bell_huang 0:242cf8f28bf2 238 {
bell_huang 0:242cf8f28bf2 239 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 240 goto FAIL;
bell_huang 0:242cf8f28bf2 241 }
bell_huang 0:242cf8f28bf2 242 }
bell_huang 0:242cf8f28bf2 243 }
bell_huang 0:242cf8f28bf2 244
bell_huang 0:242cf8f28bf2 245 // powerdown
bell_huang 0:242cf8f28bf2 246 if (!pah_comm_write(0x69, 0x01))
bell_huang 0:242cf8f28bf2 247 {
bell_huang 0:242cf8f28bf2 248 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 249 goto FAIL;
bell_huang 0:242cf8f28bf2 250 }
bell_huang 0:242cf8f28bf2 251
bell_huang 0:242cf8f28bf2 252 return pah_success;
bell_huang 0:242cf8f28bf2 253
bell_huang 0:242cf8f28bf2 254 FAIL:
bell_huang 0:242cf8f28bf2 255 debug_printf_1("pah_8011_shutdown() failed. ret = %d \n", ret);
bell_huang 0:242cf8f28bf2 256 return ret;
bell_huang 0:242cf8f28bf2 257 }
bell_huang 0:242cf8f28bf2 258
bell_huang 0:242cf8f28bf2 259 pah_ret pah_8011_read_device_package(device_package_e *device_package)
bell_huang 0:242cf8f28bf2 260 {
bell_huang 0:242cf8f28bf2 261 pah_ret ret = pah_err_unknown;
bell_huang 0:242cf8f28bf2 262 uint8_t data = 0;
bell_huang 0:242cf8f28bf2 263
bell_huang 0:242cf8f28bf2 264 if (!device_package)
bell_huang 0:242cf8f28bf2 265 {
bell_huang 0:242cf8f28bf2 266 ret = pah_err_invalid_program;
bell_huang 0:242cf8f28bf2 267 goto FAIL;
bell_huang 0:242cf8f28bf2 268 }
bell_huang 0:242cf8f28bf2 269
bell_huang 0:242cf8f28bf2 270 if (!pah_comm_write(0x7F, 0x02)) //bank2
bell_huang 0:242cf8f28bf2 271 {
bell_huang 0:242cf8f28bf2 272 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 273 goto FAIL;
bell_huang 0:242cf8f28bf2 274 }
bell_huang 0:242cf8f28bf2 275 if (!pah_comm_read(0x4A, &data))
bell_huang 0:242cf8f28bf2 276 {
bell_huang 0:242cf8f28bf2 277 ret = pah_err_platform_fail;
bell_huang 0:242cf8f28bf2 278 goto FAIL;
bell_huang 0:242cf8f28bf2 279 }
bell_huang 0:242cf8f28bf2 280
bell_huang 0:242cf8f28bf2 281 data = PAH_CHECK_BIT(data, 0);
bell_huang 0:242cf8f28bf2 282
bell_huang 0:242cf8f28bf2 283 *device_package = (device_package_e)data;
bell_huang 0:242cf8f28bf2 284
bell_huang 0:242cf8f28bf2 285 return pah_success;
bell_huang 0:242cf8f28bf2 286
bell_huang 0:242cf8f28bf2 287 FAIL:
bell_huang 0:242cf8f28bf2 288 debug_printf_1("pah_8011_read_device_package() failed. ret = %d \n", ret);
bell_huang 0:242cf8f28bf2 289 return ret;
bell_huang 0:242cf8f28bf2 290 }