Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pin_programming.c 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <avr/io.h>
  2. #include <stdint.h>
  3. #include "pin_programming.h"
  4. /* Pin definitions */
  5. #define PIN_PROG_1_DDR DDRB
  6. #define PIN_PROG_1_PORT PORTB
  7. #define PIN_PROG_1_PIN PB6
  8. #define PIN_PROG_1_PORTIN PINB
  9. #define PIN_PROG_2_DDR DDRB
  10. #define PIN_PROG_2_PORT PORTB
  11. #define PIN_PROG_2_PIN PB7
  12. #define PIN_PROG_2_PORTIN PINB
  13. #define PIN_PROG_3_DDR DDRD
  14. #define PIN_PROG_3_PORT PORTD
  15. #define PIN_PROG_3_PIN PD4
  16. #define PIN_PROG_3_PORTIN PIND
  17. void Configure_Pin_Programming_Pins(void)
  18. {
  19. /* Set pins as input */
  20. PIN_PROG_1_DDR &= ~(1 << PIN_PROG_1_PIN);
  21. PIN_PROG_2_DDR &= ~(1 << PIN_PROG_2_PIN);
  22. PIN_PROG_3_DDR &= ~(1 << PIN_PROG_3_PIN);
  23. /* Enable pull-ups */ // TODO: enable once the boards have been fixed!
  24. PIN_PROG_1_PORT |= (1 << PIN_PROG_1_PIN);
  25. PIN_PROG_2_PORT |= (1 << PIN_PROG_2_PIN);
  26. PIN_PROG_3_PORT |= (1 << PIN_PROG_3_PIN);
  27. }
  28. uint8_t Get_Own_Identifier(void)
  29. {
  30. /* The upper four bits of the ID are the module ID while the lower four bits are the serial
  31. * number set by the pin programming.
  32. * Switch 3 corresponds to bit 0
  33. * Switch 2 corresponds to bit 1
  34. * Switch 1 corresponds to bit 2
  35. */
  36. uint8_t id = (MODULE_ID_SENSOR << 4);
  37. id |= ((((PIN_PROG_3_PORTIN & (1 << PIN_PROG_3_PIN)) == 0) << 0) | \
  38. (((PIN_PROG_2_PORTIN & (1 << PIN_PROG_2_PIN)) == 0) << 1) | \
  39. (((PIN_PROG_1_PORTIN & (1 << PIN_PROG_1_PIN)) == 0) << 2));
  40. return id;
  41. }