123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /*
- * board.c
- *
- * Created on: Jun 15, 2019
- * Author: curiousmuch
- */
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/gpio.h"
- #include "driver/adc.h"
- #include "board.h"
- // Debugging IO Functions
- inline void IRAM_ATTR enable_debug_IO(uint32_t io_num)
- {
- gpio_set_level(io_num, 1);
- }
- inline void IRAM_ATTR disable_debug_IO(uint32_t io_num)
- {
- gpio_set_level(io_num, 0);
- }
- // Red LED Functions
- void enable_red_led(void)
- {
- gpio_set_level(RED_LED, 1);
- }
- void disable_red_led(void)
- {
- gpio_set_level(RED_LED, 0);
- }
- // Green LED Functions
- void enable_green_led(void)
- {
- gpio_set_level(GREEN_LED, 1);
- }
- void disable_green_led(void)
- {
- gpio_set_level(GREEN_LED, 0);
- }
- int32_t battery_measure(void)
- {
- adc1_config_width(ADC_WIDTH_BIT_12);
- adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_DB_0);
- int val = adc1_get_raw(BATTERY_ADC_CHANNEL);
- return val;
- }
- void board_init(void)
- {
- // setup LED IO
- gpio_config_t led_pin_config =
- {
- .pin_bit_mask = (uint64_t) (BIT64(RED_LED)|BIT64(GREEN_LED)),
- .mode = GPIO_MODE_OUTPUT,
- .pull_up_en = GPIO_PULLUP_DISABLE,
- .pull_down_en = GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE
- };
- gpio_config(&led_pin_config);
- // setup debugging IO
- gpio_config_t debug_pin_config =
- {
- .pin_bit_mask = (uint64_t) (BIT64(DEBUG_0)|BIT64(DEBUG_1)|BIT64(DEBUG_2)|BIT64(DEBUG_3)),
- .mode = GPIO_MODE_OUTPUT,
- .pull_up_en = GPIO_PULLUP_DISABLE,
- .pull_down_en = GPIO_PULLDOWN_DISABLE,
- .intr_type = GPIO_INTR_DISABLE
- };
- gpio_config(&debug_pin_config);
- }
|