/*! * \file hal.h * * Copyright (C) 2020 Choutouridis Christos (http://www.houtouridis.net) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #ifndef DRIVERS_HAL_H_ #define DRIVERS_HAL_H_ #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif int hal_hw_init (void); /* * ========== LCD =========== */ void lcd_init (void); void lcd_enable (uint8_t en) ; int lcd_putchar (char c); int lcd_puts (const char *s); /* * ========== Led interface ========== */ void led_red (uint8_t en); void led_green (uint8_t en); /* * ========= Relay =========== */ void relay(uint8_t on); /* * ========= Temperature =========== */ // OneWire commands #define SKIPROM 0xCC // Skip ROM matching transition #define STARTCONV 0x44 // Tells device to take a temperature reading and put it on the scratchpad #define COPYSCRATCH 0x48 // Copy EEPROM #define READSCRATCH 0xBE // Read EEPROM #define WRITESCRATCH 0x4E // Write to EEPROM #define RECALLSCRATCH 0xB8 // Reload from last known #define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power #define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition // Device resolution #define TEMP_9_BIT 0x1F // 9 bit #define TEMP_10_BIT 0x3F // 10 bit #define TEMP_11_BIT 0x5F // 11 bit #define TEMP_12_BIT 0x7F // 12 bit #define IS_TEMP_RESOLUTION(x) \ ((x == TEMP_9_BIT) || (x == TEMP_10_BIT) || (x == TEMP_11_BIT) || (x == TEMP_12_BIT)) int temp_init (uint8_t resolution); float temp_read (void); /* * ========= Proximity =========== */ #define PROX_TIME_MAX 25 // [msec] #define PROX_READINGS 7 // How many readings for averaging #define PROX_MAX_DISTANSE 450 // [cm] typedef struct { float_t readings[7]; int iter; } proximity_t; void proximity_init (proximity_t* p); float_t proximity (proximity_t* p); /* * Public data types / classes */ extern alcd_t alcd; extern ow_uart_t ow; extern proximity_t prox; #ifdef __cplusplus } #endif #endif /* DRIVERS_HAL_H_ */