Rev 1910 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1421 | linlun | 1 | |
| 2 | #include "sns_input.h" |
||
| 3 | uint8_t pinStatus[8]; |
||
| 1515 | arune | 4 | #define HIGH 1 |
| 5 | #define LOW 2 |
||
| 6 | #define NOCHANGE 0 |
||
| 7 | #define HIGH_NOCH 3 |
||
| 8 | #define LOW_NOCH 4 |
||
| 9 | |||
| 10 | #define IO_HIGH 1 |
||
| 11 | #define IO_LOW 0 |
||
| 12 | |||
| 1826 | arune | 13 | #ifndef sns_input_SEND_PERIODIC |
| 14 | #define sns_input_SEND_PERIODIC 0 |
||
| 15 | #endif |
||
| 16 | |||
| 1524 | arune | 17 | /* |
| 1515 | arune | 18 | |
| 1524 | arune | 19 | Callback function that is called from pin-change driver on AVR IO |
| 20 | id gives which pin that changed, status is the new state of the changed pin |
||
| 21 | |||
| 22 | */ |
||
| 1421 | linlun | 23 | void sns_input_pcint_callback(uint8_t id, uint8_t status) |
| 24 | { |
||
| 25 | #ifdef sns_input_CH0 |
||
| 1514 | arune | 26 | #if sns_input_CH0PCA95xxIO==0 |
| 1421 | linlun | 27 | if (id == sns_input_PCINT_CH0) { |
| 1515 | arune | 28 | if (IO_LOW != status) { |
| 1421 | linlun | 29 | pinStatus[0] = HIGH; |
| 30 | } else { |
||
| 31 | pinStatus[0] = LOW; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | #endif |
||
| 1514 | arune | 35 | #endif |
| 1421 | linlun | 36 | #ifdef sns_input_CH1 |
| 1514 | arune | 37 | #if sns_input_CH1PCA95xxIO==0 |
| 1421 | linlun | 38 | if (id == sns_input_PCINT_CH1) { |
| 1515 | arune | 39 | if (IO_LOW != status) { |
| 1421 | linlun | 40 | pinStatus[1] = HIGH; |
| 41 | } else { |
||
| 42 | pinStatus[1] = LOW; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | #endif |
||
| 1514 | arune | 46 | #endif |
| 1421 | linlun | 47 | #ifdef sns_input_CH2 |
| 1514 | arune | 48 | #if sns_input_CH2PCA95xxIO==0 |
| 1421 | linlun | 49 | if (id == sns_input_PCINT_CH2) { |
| 1515 | arune | 50 | if (IO_LOW != status) { |
| 1421 | linlun | 51 | pinStatus[2] = HIGH; |
| 52 | } else { |
||
| 53 | pinStatus[2] = LOW; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | #endif |
||
| 1514 | arune | 57 | #endif |
| 1421 | linlun | 58 | #ifdef sns_input_CH3 |
| 1514 | arune | 59 | #if sns_input_CH3PCA95xxIO==0 |
| 1421 | linlun | 60 | if (id == sns_input_PCINT_CH3) { |
| 1515 | arune | 61 | if (IO_LOW != status) { |
| 1421 | linlun | 62 | pinStatus[3] = HIGH; |
| 63 | } else { |
||
| 64 | pinStatus[3] = LOW; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | #endif |
||
| 1514 | arune | 68 | #endif |
| 1421 | linlun | 69 | #ifdef sns_input_CH4 |
| 1514 | arune | 70 | #if sns_input_CH4PCA95xxIO==0 |
| 1421 | linlun | 71 | if (id == sns_input_PCINT_CH4) { |
| 1515 | arune | 72 | if (IO_LOW != status) { |
| 1421 | linlun | 73 | pinStatus[4] = HIGH; |
| 74 | } else { |
||
| 75 | pinStatus[4] = LOW; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | #endif |
||
| 1514 | arune | 79 | #endif |
| 1421 | linlun | 80 | #ifdef sns_input_CH5 |
| 1514 | arune | 81 | #if sns_input_CH5PCA95xxIO==0 |
| 1421 | linlun | 82 | if (id == sns_input_PCINT_CH5) { |
| 1515 | arune | 83 | if (IO_LOW != status) { |
| 1421 | linlun | 84 | pinStatus[5] = HIGH; |
| 85 | } else { |
||
| 86 | pinStatus[5] = LOW; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | #endif |
||
| 1514 | arune | 90 | #endif |
| 1421 | linlun | 91 | #ifdef sns_input_CH6 |
| 1514 | arune | 92 | #if sns_input_CH6PCA95xxIO==0 |
| 1421 | linlun | 93 | if (id == sns_input_PCINT_CH6) { |
| 1515 | arune | 94 | if (IO_LOW != status) { |
| 1421 | linlun | 95 | pinStatus[6] = HIGH; |
| 96 | } else { |
||
| 97 | pinStatus[6] = LOW; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | #endif |
||
| 1514 | arune | 101 | #endif |
| 1421 | linlun | 102 | #ifdef sns_input_CH7 |
| 1514 | arune | 103 | #if sns_input_CH7PCA95xxIO==0 |
| 1421 | linlun | 104 | if (id == sns_input_PCINT_CH7) { |
| 1515 | arune | 105 | if (IO_LOW != status) { |
| 1421 | linlun | 106 | pinStatus[7] = HIGH; |
| 107 | } else { |
||
| 108 | pinStatus[7] = LOW; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | #endif |
||
| 1514 | arune | 112 | #endif |
| 1421 | linlun | 113 | } |
| 114 | |||
| 1524 | arune | 115 | |
| 116 | #if sns_input_ENABLE_PCA95xx==1 |
||
| 117 | /* |
||
| 118 | |||
| 119 | Callback function that is called from PCA95xx-driver when any pin has changed |
||
| 120 | status is the pin status of all pins on PCA95xx |
||
| 121 | |||
| 122 | */ |
||
| 123 | void sns_input_PCA95xx_callback(uint16_t status) |
||
| 1514 | arune | 124 | { |
| 1524 | arune | 125 | #ifdef sns_input_CH0 |
| 126 | #if sns_input_CH0PCA95xxIO==1 |
||
| 127 | if (pinStatus[0] == LOW_NOCH && ((status>>sns_input_CH0)&0x1) == IO_HIGH) { |
||
| 128 | pinStatus[0] = HIGH; |
||
| 129 | } else if (pinStatus[0] == HIGH_NOCH && ((status>>sns_input_CH0)&0x1) == IO_LOW) { |
||
| 130 | pinStatus[0] = LOW; |
||
| 131 | } |
||
| 132 | #endif |
||
| 133 | #endif |
||
| 134 | #ifdef sns_input_CH1 |
||
| 135 | #if sns_input_CH1PCA95xxIO==1 |
||
| 136 | if (pinStatus[1] == LOW_NOCH && ((status>>sns_input_CH1)&0x1) == IO_HIGH) { |
||
| 137 | pinStatus[1] = HIGH; |
||
| 138 | } else if (pinStatus[1] == HIGH_NOCH && ((status>>sns_input_CH1)&0x1) == IO_LOW) { |
||
| 139 | pinStatus[1] = LOW; |
||
| 140 | } |
||
| 141 | #endif |
||
| 142 | #endif |
||
| 143 | #ifdef sns_input_CH2 |
||
| 144 | #if sns_input_CH2PCA95xxIO==1 |
||
| 145 | if (pinStatus[2] == LOW_NOCH && ((status>>sns_input_CH2)&0x1) == IO_HIGH) { |
||
| 146 | pinStatus[2] = HIGH; |
||
| 147 | } else if (pinStatus[2] == HIGH_NOCH && ((status>>sns_input_CH2)&0x1) == IO_LOW) { |
||
| 148 | pinStatus[2] = LOW; |
||
| 149 | } |
||
| 150 | #endif |
||
| 151 | #endif |
||
| 152 | #ifdef sns_input_CH3 |
||
| 153 | #if sns_input_CH3PCA95xxIO==1 |
||
| 154 | if (pinStatus[3] == LOW_NOCH && ((status>>sns_input_CH3)&0x1) == IO_HIGH) { |
||
| 155 | pinStatus[3] = HIGH; |
||
| 156 | } else if (pinStatus[3] == HIGH_NOCH && ((status>>sns_input_CH3)&0x1) == IO_LOW) { |
||
| 157 | pinStatus[3] = LOW; |
||
| 158 | } |
||
| 159 | #endif |
||
| 160 | #endif |
||
| 161 | #ifdef sns_input_CH4 |
||
| 162 | #if sns_input_CH4PCA95xxIO==1 |
||
| 163 | if (pinStatus[4] == LOW_NOCH && ((status>>sns_input_CH4)&0x1) == IO_HIGH) { |
||
| 164 | pinStatus[4] = HIGH; |
||
| 165 | } else if (pinStatus[4] == HIGH_NOCH && ((status>>sns_input_CH4)&0x1) == IO_LOW) { |
||
| 166 | pinStatus[4] = LOW; |
||
| 167 | } |
||
| 168 | #endif |
||
| 169 | #endif |
||
| 170 | |||
| 171 | #ifdef sns_input_CH5 |
||
| 172 | #if sns_input_CH5PCA95xxIO==1 |
||
| 173 | if (pinStatus[5] == LOW_NOCH && ((status>>sns_input_CH5)&0x1) == IO_HIGH) { |
||
| 174 | pinStatus[5] = HIGH; |
||
| 175 | } else if (pinStatus[5] == HIGH_NOCH && ((status>>sns_input_CH5)&0x1) == IO_LOW) { |
||
| 176 | pinStatus[5] = LOW; |
||
| 177 | } |
||
| 178 | #endif |
||
| 179 | #endif |
||
| 180 | #ifdef sns_input_CH6 |
||
| 181 | #if sns_input_CH0PCA95xxIO==1 |
||
| 182 | if (pinStatus[6] == LOW_NOCH && ((status>>sns_input_CH6)&0x1) == IO_HIGH) { |
||
| 183 | pinStatus[6] = HIGH; |
||
| 184 | } else if (pinStatus[6] == HIGH_NOCH && ((status>>sns_input_CH6)&0x1) == IO_LOW) { |
||
| 185 | pinStatus[6] = LOW; |
||
| 186 | } |
||
| 187 | #endif |
||
| 188 | #endif |
||
| 189 | #ifdef sns_input_CH7 |
||
| 190 | #if sns_input_CH7PCA95xxIO==1 |
||
| 191 | if (pinStatus[7] == LOW_NOCH && ((status>>sns_input_CH7)&0x1) == IO_HIGH) { |
||
| 192 | pinStatus[7] = HIGH; |
||
| 193 | } else if (pinStatus[7] == HIGH_NOCH && ((status>>sns_input_CH7)&0x1) == IO_LOW) { |
||
| 194 | pinStatus[7] = LOW; |
||
| 195 | } |
||
| 196 | #endif |
||
| 197 | #endif |
||
| 198 | |||
| 199 | } |
||
| 1514 | arune | 200 | #endif |
| 201 | |||
| 202 | |||
| 1524 | arune | 203 | /* |
| 204 | |||
| 1826 | arune | 205 | Function that initiates status variables for pins |
| 1524 | arune | 206 | called at statup |
| 207 | |||
| 208 | */ |
||
| 1826 | arune | 209 | void sns_input_setPinStatus(void) |
| 1515 | arune | 210 | { |
| 1826 | arune | 211 | #if sns_input_ENABLE_PCA95xx==1 |
| 1515 | arune | 212 | uint16_t status = Pca95xx_GetInputs(); |
| 1826 | arune | 213 | #endif |
| 1515 | arune | 214 | #ifdef sns_input_CH0 |
| 215 | #if sns_input_CH0PCA95xxIO==1 |
||
| 216 | if (((status>>sns_input_CH0)&0x1) != IO_LOW) { |
||
| 217 | pinStatus[0] = HIGH_NOCH; |
||
| 218 | } else { |
||
| 219 | pinStatus[0] = LOW_NOCH; |
||
| 220 | } |
||
| 1826 | arune | 221 | #else |
| 222 | if (gpio_get_state(sns_input_CH0)) { |
||
| 223 | pinStatus[0] = HIGH_NOCH; |
||
| 224 | } else { |
||
| 225 | pinStatus[0] = LOW_NOCH; |
||
| 226 | } |
||
| 1515 | arune | 227 | #endif |
| 228 | #endif |
||
| 229 | #ifdef sns_input_CH1 |
||
| 230 | #if sns_input_CH1PCA95xxIO==1 |
||
| 231 | if (((status>>sns_input_CH1)&0x1) != IO_LOW) { |
||
| 232 | pinStatus[1] = HIGH_NOCH; |
||
| 233 | } else { |
||
| 234 | pinStatus[1] = LOW_NOCH; |
||
| 235 | } |
||
| 1826 | arune | 236 | #else |
| 237 | if (gpio_get_state(sns_input_CH1)) { |
||
| 238 | pinStatus[1] = HIGH_NOCH; |
||
| 239 | } else { |
||
| 240 | pinStatus[1] = LOW_NOCH; |
||
| 241 | } |
||
| 1515 | arune | 242 | #endif |
| 243 | #endif |
||
| 244 | #ifdef sns_input_CH2 |
||
| 245 | #if sns_input_CH2PCA95xxIO==1 |
||
| 246 | if (((status>>sns_input_CH2)&0x1) != IO_LOW) { |
||
| 247 | pinStatus[2] = HIGH_NOCH; |
||
| 248 | } else { |
||
| 249 | pinStatus[2] = LOW_NOCH; |
||
| 250 | } |
||
| 1826 | arune | 251 | #else |
| 252 | if (gpio_get_state(sns_input_CH2)) { |
||
| 253 | pinStatus[2] = HIGH_NOCH; |
||
| 254 | } else { |
||
| 255 | pinStatus[2] = LOW_NOCH; |
||
| 256 | } |
||
| 1515 | arune | 257 | #endif |
| 258 | #endif |
||
| 259 | #ifdef sns_input_CH3 |
||
| 260 | #if sns_input_CH3PCA95xxIO==1 |
||
| 261 | if (((status>>sns_input_CH3)&0x1) != IO_LOW) { |
||
| 262 | pinStatus[3] = HIGH_NOCH; |
||
| 263 | } else { |
||
| 264 | pinStatus[3] = LOW_NOCH; |
||
| 265 | } |
||
| 1826 | arune | 266 | #else |
| 267 | if (gpio_get_state(sns_input_CH3)) { |
||
| 268 | pinStatus[3] = HIGH_NOCH; |
||
| 269 | } else { |
||
| 270 | pinStatus[3] = LOW_NOCH; |
||
| 271 | } |
||
| 1515 | arune | 272 | #endif |
| 273 | #endif |
||
| 274 | #ifdef sns_input_CH4 |
||
| 275 | #if sns_input_CH4PCA95xxIO==1 |
||
| 276 | if (((status>>sns_input_CH4)&0x1) != IO_LOW) { |
||
| 277 | pinStatus[4] = HIGH_NOCH; |
||
| 278 | } else { |
||
| 279 | pinStatus[4] = LOW_NOCH; |
||
| 280 | } |
||
| 1826 | arune | 281 | #else |
| 282 | if (gpio_get_state(sns_input_CH4)) { |
||
| 283 | pinStatus[4] = HIGH_NOCH; |
||
| 284 | } else { |
||
| 285 | pinStatus[4] = LOW_NOCH; |
||
| 286 | } |
||
| 1515 | arune | 287 | #endif |
| 288 | #endif |
||
| 289 | #ifdef sns_input_CH5 |
||
| 290 | #if sns_input_CH5PCA95xxIO==1 |
||
| 291 | if (((status>>sns_input_CH5)&0x1) != IO_LOW) { |
||
| 292 | pinStatus[5] = HIGH_NOCH; |
||
| 293 | } else { |
||
| 294 | pinStatus[5] = LOW_NOCH; |
||
| 295 | } |
||
| 1826 | arune | 296 | #else |
| 297 | if (gpio_get_state(sns_input_CH5)) { |
||
| 298 | pinStatus[5] = HIGH_NOCH; |
||
| 299 | } else { |
||
| 300 | pinStatus[5] = LOW_NOCH; |
||
| 301 | } |
||
| 1515 | arune | 302 | #endif |
| 303 | #endif |
||
| 304 | #ifdef sns_input_CH6 |
||
| 305 | #if sns_input_CH6PCA95xxIO==1 |
||
| 306 | if (((status>>sns_input_CH6)&0x1) != IO_LOW) { |
||
| 307 | pinStatus[6] = HIGH_NOCH; |
||
| 308 | } else { |
||
| 309 | pinStatus[6] = LOW_NOCH; |
||
| 310 | } |
||
| 1826 | arune | 311 | #else |
| 312 | if (gpio_get_state(sns_input_CH6)) { |
||
| 313 | pinStatus[6] = HIGH_NOCH; |
||
| 314 | } else { |
||
| 315 | pinStatus[6] = LOW_NOCH; |
||
| 316 | } |
||
| 1515 | arune | 317 | #endif |
| 318 | #endif |
||
| 319 | #ifdef sns_input_CH7 |
||
| 320 | #if sns_input_CH7PCA95xxIO==1 |
||
| 321 | if (((status>>sns_input_CH7)&0x1) != IO_LOW) { |
||
| 322 | pinStatus[7] = HIGH_NOCH; |
||
| 323 | } else { |
||
| 324 | pinStatus[7] = LOW_NOCH; |
||
| 325 | } |
||
| 1826 | arune | 326 | #else |
| 327 | if (gpio_get_state(sns_input_CH7)) { |
||
| 328 | pinStatus[7] = HIGH_NOCH; |
||
| 329 | } else { |
||
| 330 | pinStatus[7] = LOW_NOCH; |
||
| 331 | } |
||
| 1515 | arune | 332 | #endif |
| 333 | #endif |
||
| 334 | } |
||
| 335 | |||
| 1421 | linlun | 336 | void sns_input_Init(void) |
| 337 | { |
||
| 1524 | arune | 338 | #if sns_input_ENABLE_PCA95xx==1 |
| 339 | Pca95xx_SetCallback(sns_input_PCA95XX_CALLBACK_INDEX, &sns_input_PCA95xx_callback); |
||
| 1518 | arune | 340 | Pca95xx_Init(0); |
| 341 | #endif |
||
| 342 | |||
| 1421 | linlun | 343 | #ifdef sns_input_CH0 |
| 1514 | arune | 344 | #if sns_input_CH0PCA95xxIO==0 |
| 1421 | linlun | 345 | #if (sns_input_CH0_pullup == 1) |
| 346 | gpio_set_pullup(sns_input_CH0); |
||
| 347 | #else |
||
| 348 | gpio_clr_pullup(sns_input_CH0); |
||
| 349 | #endif |
||
| 350 | gpio_set_in(sns_input_CH0); |
||
| 351 | Pcint_SetCallbackPin(sns_input_PCINT_CH0, sns_input_CH0, &sns_input_pcint_callback); |
||
| 1514 | arune | 352 | #else |
| 353 | Pca95xx_set_in(sns_input_CH0); |
||
| 354 | #endif |
||
| 1421 | linlun | 355 | #endif |
| 356 | #ifdef sns_input_CH1 |
||
| 1514 | arune | 357 | #if sns_input_CH1PCA95xxIO==0 |
| 1421 | linlun | 358 | #if (sns_input_CH1_pullup == 1) |
| 359 | gpio_set_pullup(sns_input_CH1); |
||
| 360 | #else |
||
| 361 | gpio_clr_pullup(sns_input_CH1); |
||
| 362 | #endif |
||
| 363 | gpio_set_in(sns_input_CH1); |
||
| 364 | Pcint_SetCallbackPin(sns_input_PCINT_CH1, sns_input_CH1, &sns_input_pcint_callback); |
||
| 1514 | arune | 365 | #else |
| 366 | Pca95xx_set_in(sns_input_CH1); |
||
| 367 | #endif |
||
| 1421 | linlun | 368 | #endif |
| 369 | #ifdef sns_input_CH2 |
||
| 1514 | arune | 370 | #if sns_input_CH2PCA95xxIO==0 |
| 1421 | linlun | 371 | #if (sns_input_CH2_pullup == 1) |
| 372 | gpio_set_pullup(sns_input_CH2); |
||
| 373 | #else |
||
| 374 | gpio_clr_pullup(sns_input_CH2); |
||
| 375 | #endif |
||
| 376 | gpio_set_in(sns_input_CH2); |
||
| 377 | Pcint_SetCallbackPin(sns_input_PCINT_CH2, sns_input_CH2, &sns_input_pcint_callback); |
||
| 1514 | arune | 378 | #else |
| 379 | Pca95xx_set_in(sns_input_CH2); |
||
| 380 | #endif |
||
| 1421 | linlun | 381 | #endif |
| 382 | #ifdef sns_input_CH3 |
||
| 1514 | arune | 383 | #if sns_input_CH3PCA95xxIO==0 |
| 1421 | linlun | 384 | #if (sns_input_CH3_pullup == 1) |
| 385 | gpio_set_pullup(sns_input_CH3); |
||
| 386 | #else |
||
| 387 | gpio_clr_pullup(sns_input_CH3); |
||
| 388 | #endif |
||
| 389 | gpio_set_in(sns_input_CH3); |
||
| 390 | Pcint_SetCallbackPin(sns_input_PCINT_CH3, sns_input_CH3, &sns_input_pcint_callback); |
||
| 1514 | arune | 391 | #else |
| 392 | Pca95xx_set_in(sns_input_CH3); |
||
| 393 | #endif |
||
| 1421 | linlun | 394 | #endif |
| 395 | #ifdef sns_input_CH4 |
||
| 1514 | arune | 396 | #if sns_input_CH4PCA95xxIO==0 |
| 1421 | linlun | 397 | #if (sns_input_CH4_pullup == 1) |
| 398 | gpio_set_pullup(sns_input_CH4); |
||
| 399 | #else |
||
| 400 | gpio_clr_pullup(sns_input_CH4); |
||
| 401 | #endif |
||
| 402 | gpio_set_in(sns_input_CH4); |
||
| 403 | Pcint_SetCallbackPin(sns_input_PCINT_CH4, sns_input_CH4, &sns_input_pcint_callback); |
||
| 1514 | arune | 404 | #else |
| 405 | Pca95xx_set_in(sns_input_CH4); |
||
| 406 | #endif |
||
| 1421 | linlun | 407 | #endif |
| 408 | #ifdef sns_input_CH5 |
||
| 1514 | arune | 409 | #if sns_input_CH5PCA95xxIO==0 |
| 1421 | linlun | 410 | #if (sns_input_CH5_pullup == 1) |
| 411 | gpio_set_pullup(sns_input_CH5); |
||
| 412 | #else |
||
| 413 | gpio_clr_pullup(sns_input_CH5); |
||
| 414 | #endif |
||
| 415 | gpio_set_in(sns_input_CH5); |
||
| 416 | Pcint_SetCallbackPin(sns_input_PCINT_CH5, sns_input_CH5, &sns_input_pcint_callback); |
||
| 1514 | arune | 417 | #else |
| 418 | Pca95xx_set_in(sns_input_CH5); |
||
| 419 | #endif |
||
| 1421 | linlun | 420 | #endif |
| 421 | #ifdef sns_input_CH6 |
||
| 1514 | arune | 422 | #if sns_input_CH6PCA95xxIO==0 |
| 1421 | linlun | 423 | #if (sns_input_CH6_pullup == 1) |
| 424 | gpio_set_pullup(sns_input_CH6); |
||
| 425 | #else |
||
| 426 | gpio_clr_pullup(sns_input_CH6); |
||
| 427 | #endif |
||
| 428 | gpio_set_in(sns_input_CH6); |
||
| 429 | Pcint_SetCallbackPin(sns_input_PCINT_CH6, sns_input_CH6, &sns_input_pcint_callback); |
||
| 1514 | arune | 430 | #else |
| 431 | Pca95xx_set_in(sns_input_CH6); |
||
| 432 | #endif |
||
| 1421 | linlun | 433 | #endif |
| 434 | #ifdef sns_input_CH7 |
||
| 1514 | arune | 435 | #if sns_input_CH7PCA95xxIO==0 |
| 1421 | linlun | 436 | #if (sns_input_CH7_pullup == 1) |
| 437 | gpio_set_pullup(sns_input_CH7); |
||
| 438 | #else |
||
| 439 | gpio_clr_pullup(sns_input_CH7); |
||
| 440 | #endif |
||
| 441 | gpio_set_in(sns_input_CH7); |
||
| 442 | Pcint_SetCallbackPin(sns_input_PCINT_CH7, sns_input_CH7, &sns_input_pcint_callback); |
||
| 1514 | arune | 443 | #else |
| 444 | Pca95xx_set_in(sns_input_CH7); |
||
| 445 | #endif |
||
| 1421 | linlun | 446 | #endif |
| 447 | |||
| 1518 | arune | 448 | |
| 1826 | arune | 449 | sns_input_setPinStatus(); |
| 450 | |||
| 1524 | arune | 451 | Timer_SetTimeout(sns_input_DEBOUNCE_TIMER, sns_input_DEBOUNCE_TIME_MS, TimerTypeFreeRunning, 0); |
| 2030 | linlun | 452 | #if sns_input_SEND_PERIODIC==1 |
| 1826 | arune | 453 | Timer_SetTimeout(sns_input_SEND_PERIODIC_TIMER, sns_input_SEND_PERIOD_MS, TimerTypeFreeRunning, 0); |
| 2030 | linlun | 454 | #endif |
| 1421 | linlun | 455 | } |
| 456 | |||
| 1826 | arune | 457 | #if sns_input_SEND_PERIODIC==1 |
| 458 | uint8_t ChannelToSend = 0; |
||
| 459 | #endif |
||
| 1421 | linlun | 460 | void sns_input_Process(void) |
| 461 | { |
||
| 1524 | arune | 462 | if (Timer_Expired(sns_input_DEBOUNCE_TIMER)) |
| 463 | { |
||
| 464 | uint8_t index = 0; |
||
| 465 | for (index = 0; index < 8; index++) { |
||
| 466 | if (pinStatus[index] == LOW || pinStatus[index] == HIGH) { |
||
| 467 | StdCan_Msg_t txMsg; |
||
| 468 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
||
| 469 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 470 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_INPUT; |
||
| 471 | txMsg.Header.ModuleId = sns_input_ID; |
||
| 472 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PINSTATUS; |
||
| 473 | txMsg.Length = 2; |
||
| 474 | txMsg.Data[0] = index; |
||
| 475 | if (pinStatus[index] == HIGH) { |
||
| 476 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 477 | pinStatus[index] = HIGH_NOCH; |
||
| 478 | } else { |
||
| 479 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 480 | pinStatus[index] = LOW_NOCH; |
||
| 481 | } |
||
| 1826 | arune | 482 | StdCan_Put(&txMsg); |
| 1421 | linlun | 483 | } |
| 484 | } |
||
| 485 | } |
||
| 1826 | arune | 486 | |
| 487 | #if sns_input_SEND_PERIODIC==1 |
||
| 488 | if (Timer_Expired(sns_input_SEND_PERIODIC_TIMER)) |
||
| 489 | { |
||
| 490 | StdCan_Msg_t txMsg; |
||
| 491 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
||
| 492 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 493 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_INPUT; |
||
| 494 | txMsg.Header.ModuleId = sns_input_ID; |
||
| 495 | txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PINSTATUS; |
||
| 496 | txMsg.Length = 2; |
||
| 497 | txMsg.Data[0] = ChannelToSend; |
||
| 498 | #ifdef sns_input_CH0 |
||
| 499 | if (ChannelToSend==0) |
||
| 500 | { |
||
| 501 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 502 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 503 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 504 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 505 | } |
||
| 506 | |||
| 507 | StdCan_Put(&txMsg); |
||
| 508 | } |
||
| 509 | #endif |
||
| 510 | #ifdef sns_input_CH1 |
||
| 511 | if (ChannelToSend==1) |
||
| 512 | { |
||
| 513 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 514 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 515 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 516 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 517 | } |
||
| 518 | |||
| 519 | StdCan_Put(&txMsg); |
||
| 520 | } |
||
| 521 | #endif |
||
| 522 | #ifdef sns_input_CH2 |
||
| 523 | if (ChannelToSend==2) |
||
| 524 | { |
||
| 525 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 526 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 527 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 528 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 529 | } |
||
| 530 | |||
| 531 | StdCan_Put(&txMsg); |
||
| 532 | } |
||
| 533 | #endif |
||
| 534 | #ifdef sns_input_CH3 |
||
| 535 | if (ChannelToSend==3) |
||
| 536 | { |
||
| 537 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 538 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 539 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 540 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 541 | } |
||
| 542 | |||
| 543 | StdCan_Put(&txMsg); |
||
| 544 | } |
||
| 545 | #endif |
||
| 546 | #ifdef sns_input_CH4 |
||
| 547 | if (ChannelToSend==4) |
||
| 548 | { |
||
| 549 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 550 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 551 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 552 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 553 | } |
||
| 554 | |||
| 555 | StdCan_Put(&txMsg); |
||
| 556 | } |
||
| 557 | #endif |
||
| 558 | #ifdef sns_input_CH5 |
||
| 559 | if (ChannelToSend==5) |
||
| 560 | { |
||
| 561 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 562 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 563 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 564 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 565 | } |
||
| 566 | |||
| 567 | StdCan_Put(&txMsg); |
||
| 568 | } |
||
| 569 | #endif |
||
| 570 | #ifdef sns_input_CH6 |
||
| 571 | if (ChannelToSend==6) |
||
| 572 | { |
||
| 573 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 574 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 575 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 576 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 577 | } |
||
| 578 | |||
| 579 | StdCan_Put(&txMsg); |
||
| 580 | } |
||
| 581 | #endif |
||
| 582 | #ifdef sns_input_CH7 |
||
| 583 | if (ChannelToSend==7) |
||
| 584 | { |
||
| 585 | if (pinStatus[ChannelToSend] == HIGH || pinStatus[ChannelToSend] == HIGH_NOCH) { |
||
| 586 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH; |
||
| 587 | } else if (pinStatus[ChannelToSend] == LOW || pinStatus[ChannelToSend] == LOW_NOCH) { |
||
| 588 | txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW; |
||
| 589 | } |
||
| 590 | |||
| 591 | StdCan_Put(&txMsg); |
||
| 592 | } |
||
| 593 | #endif |
||
| 594 | |||
| 595 | if (ChannelToSend++ >=8) |
||
| 596 | { |
||
| 597 | ChannelToSend=0; |
||
| 598 | } |
||
| 599 | } |
||
| 600 | #endif |
||
| 1421 | linlun | 601 | } |
| 602 | |||
| 603 | void sns_input_HandleMessage(StdCan_Msg_t *rxMsg) |
||
| 604 | { |
||
| 605 | |||
| 606 | } |
||
| 607 | |||
| 608 | void sns_input_List(uint8_t ModuleSequenceNumber) |
||
| 609 | { |
||
| 610 | StdCan_Msg_t txMsg; |
||
| 611 | |||
| 612 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); |
||
| 613 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 614 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_INPUT; |
||
| 615 | txMsg.Header.ModuleId = sns_input_ID; |
||
| 616 | txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST; |
||
| 617 | txMsg.Length = 6; |
||
| 618 | |||
| 1910 | arune | 619 | uint32_t HwId=BIOS_GetHwId(); |
| 620 | txMsg.Data[0] = HwId&0xff; |
||
| 621 | txMsg.Data[1] = (HwId>>8)&0xff; |
||
| 622 | txMsg.Data[2] = (HwId>>16)&0xff; |
||
| 623 | txMsg.Data[3] = (HwId>>24)&0xff; |
||
| 1421 | linlun | 624 | |
| 625 | txMsg.Data[4] = NUMBER_OF_MODULES; |
||
| 626 | txMsg.Data[5] = ModuleSequenceNumber; |
||
| 627 | |||
| 628 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |
||
| 629 | } |