Microprocessor and peripheral 2 assignments for AUTH
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.
 
 
 
 
 
 

110 lines
2.7 KiB

  1. /*!
  2. * \file hal.h
  3. *
  4. * Copyright (C) 2020 Choutouridis Christos (http://www.houtouridis.net)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation, either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifndef DRIVERS_HAL_H_
  21. #define DRIVERS_HAL_H_
  22. #include <thermostat_shield.h>
  23. #include <alcd.h>
  24. #include <jiffies.h>
  25. #include <onewire_uart.h>
  26. #include <deque08.h>
  27. #include <thermostat.h>
  28. #include <stdio.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. int hal_hw_init (void);
  33. /*
  34. * ========== LCD ===========
  35. */
  36. void lcd_init (void);
  37. void lcd_enable (uint8_t en) ;
  38. int lcd_putchar (char c);
  39. int lcd_puts (const char *s);
  40. /*
  41. * ========== Led interface ==========
  42. */
  43. void led_red (uint8_t en);
  44. void led_green (uint8_t en);
  45. /*
  46. * ========= Relay ===========
  47. */
  48. void relay(uint8_t on);
  49. /*
  50. * ========= Temperature ===========
  51. */
  52. // OneWire commands
  53. #define SKIPROM 0xCC // Skip ROM matching transition
  54. #define STARTCONV 0x44 // Tells device to take a temperature reading and put it on the scratchpad
  55. #define COPYSCRATCH 0x48 // Copy EEPROM
  56. #define READSCRATCH 0xBE // Read EEPROM
  57. #define WRITESCRATCH 0x4E // Write to EEPROM
  58. #define RECALLSCRATCH 0xB8 // Reload from last known
  59. #define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power
  60. #define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition
  61. // Device resolution
  62. #define TEMP_9_BIT 0x1F // 9 bit
  63. #define TEMP_10_BIT 0x3F // 10 bit
  64. #define TEMP_11_BIT 0x5F // 11 bit
  65. #define TEMP_12_BIT 0x7F // 12 bit
  66. #define IS_TEMP_RESOLUTION(x) \
  67. ((x == TEMP_9_BIT) || (x == TEMP_10_BIT) || (x == TEMP_11_BIT) || (x == TEMP_12_BIT))
  68. int temp_init (uint8_t resolution);
  69. float temp_read (void);
  70. /*
  71. * ========= Proximity ===========
  72. */
  73. #define PROX_TIME_MAX 25 // [msec]
  74. #define PROX_READINGS 7 // How many readings for averaging
  75. #define PROX_MAX_DISTANSE 450 // [cm]
  76. typedef struct {
  77. float_t readings[7];
  78. int iter;
  79. } proximity_t;
  80. void proximity_init (proximity_t* p);
  81. float_t proximity (proximity_t* p);
  82. /*
  83. * Public data types / classes
  84. */
  85. extern alcd_t alcd;
  86. extern ow_uart_t ow;
  87. extern proximity_t prox;
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* DRIVERS_HAL_H_ */