334 lines
7.3 KiB
C
334 lines
7.3 KiB
C
/*
|
|
* port.c
|
|
*
|
|
* Created on: Jan 16, 2023
|
|
* Author: Partha
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <inttypes.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "driver/rtc_io.h"
|
|
#include "freertos/queue.h"
|
|
#include "driver/gpio.h"
|
|
#include "port.h"
|
|
#include "uart_ifx.h"
|
|
|
|
static const char* TAG = "PORT";
|
|
|
|
#define LOG_LOCAL_LEVEL ESP_LOG_INFO
|
|
#include "esp_log.h"
|
|
|
|
#define ESP_INTR_FLAG_DEFAULT 0
|
|
|
|
<<<<<<< HEAD
|
|
#define LED_BLUE_PIN 12
|
|
#define LED_RED_PIN 13
|
|
|
|
#define UD_RAD_PWRKEY_PIN 20
|
|
#define UD_RAD_RESET_PIN 21
|
|
=======
|
|
#define LED_BLUE_PIN 26
|
|
#define LED_RED_PIN 20
|
|
#define LED_GREEN_PIN 21
|
|
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
#define MODEM_LDO_EN_PIN 33
|
|
|
|
#define RAD_STATUS_PIN 19
|
|
|
|
#define USB_CHG_STATUS_PIN 34
|
|
|
|
#define LIGHT_SENSOR_EN_PIN 35
|
|
#define ACCEL_PWN_PIN 11
|
|
|
|
#define ADC_BATT_MON_PIN 1
|
|
#define ADC_LIGHT_SEN_PIN 2
|
|
|
|
<<<<<<< HEAD
|
|
#define VBAT_SENSE_EN_PIN 14
|
|
=======
|
|
#define VBAT_SENSE_EN_PIN 42
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
|
|
#define LOWV_DETECT_PIN 38
|
|
|
|
#define PIN_MASK(x) (1ULL << x)
|
|
|
|
extern void IRAM_ATTR accel_int1_isr(void *args);
|
|
extern void IRAM_ATTR vusb_detect_isr(void *args);
|
|
extern void IRAM_ATTR lowv_detect_isr(void *args);
|
|
extern void IRAM_ATTR push_button_isr(void *args);
|
|
|
|
static bool red_led_status = 0;
|
|
static bool blue_led_status = 0;
|
|
<<<<<<< HEAD
|
|
=======
|
|
static bool green_led_status = 0;
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
|
|
static void init_outputs(void)
|
|
{
|
|
gpio_config_t io_conf = {0};
|
|
|
|
io_conf.intr_type = GPIO_INTR_DISABLE;
|
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
|
io_conf.pin_bit_mask = PIN_MASK(LED_RED_PIN) | \
|
|
PIN_MASK(LED_BLUE_PIN) | \
|
|
<<<<<<< HEAD
|
|
PIN_MASK(UD_RAD_PWRKEY_PIN) | \
|
|
PIN_MASK(UD_RAD_RESET_PIN) | \
|
|
PIN_MASK(MODEM_LDO_EN_PIN) | \
|
|
PIN_MASK(ACCEL_PWN_PIN) | \
|
|
/* PIN_MASK(LIGHT_SENSOR_EN_PIN) |*/
|
|
=======
|
|
PIN_MASK(LED_GREEN_PIN) | \
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
PIN_MASK(VBAT_SENSE_EN_PIN);
|
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
|
|
|
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
|
|
|
//Initialize all Outputs to LOW
|
|
<<<<<<< HEAD
|
|
gpio_set_level(LED_RED_PIN, 0);
|
|
gpio_set_level(LED_BLUE_PIN, 0);
|
|
gpio_set_level(UD_RAD_PWRKEY_PIN, 0);
|
|
gpio_set_level(UD_RAD_RESET_PIN, 0);
|
|
gpio_set_level(MODEM_LDO_EN_PIN, 0);
|
|
gpio_set_level(ACCEL_PWN_PIN, 0);
|
|
gpio_set_level(LIGHT_SENSOR_EN_PIN, 0);
|
|
=======
|
|
gpio_set_level(LED_RED_PIN, 1);
|
|
gpio_set_level(LED_BLUE_PIN, 1);
|
|
gpio_set_level(LED_GREEN_PIN, 1);
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
gpio_set_level(VBAT_SENSE_EN_PIN, 0);
|
|
}
|
|
|
|
static void init_inputs(void)
|
|
{
|
|
gpio_config_t io_conf = {0};
|
|
|
|
io_conf.mode = GPIO_MODE_INPUT;
|
|
io_conf.pin_bit_mask = PIN_MASK(ADC_BATT_MON_PIN) | \
|
|
PIN_MASK(ADC_LIGHT_SEN_PIN) | \
|
|
/* PIN_MASK(ALER1_IN_PIN) | \*/
|
|
PIN_MASK(ALER2_IN_PIN) | \
|
|
PIN_MASK(ALER3_IN_PIN) | \
|
|
PIN_MASK(ALER4_IN_PIN) | \
|
|
PIN_MASK(RAD_STATUS_PIN) | \
|
|
PIN_MASK(USB_CHG_STATUS_PIN);
|
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
|
|
|
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
|
}
|
|
|
|
static void init_isrs(void)
|
|
{
|
|
<<<<<<< HEAD
|
|
gpio_config_t io_conf = {0};
|
|
=======
|
|
/*gpio_config_t io_conf = {0};
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
|
|
io_conf.intr_type = GPIO_INTR_ANYEDGE;
|
|
io_conf.mode = GPIO_MODE_INPUT;
|
|
io_conf.pin_bit_mask = PIN_MASK(ACCEL_INT1_PIN) | \
|
|
PIN_MASK(VUSB_DETECT_PIN) | \
|
|
PIN_MASK(LOWV_DETECT_PIN) | \
|
|
PIN_MASK(SWITCH_INPUT_PIN);
|
|
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
|
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
|
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
|
|
|
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
|
|
gpio_isr_handler_add(ACCEL_INT1_PIN, accel_int1_isr, (void *)ACCEL_INT1_PIN);
|
|
gpio_isr_handler_add(VUSB_DETECT_PIN, vusb_detect_isr, (void *)VUSB_DETECT_PIN);
|
|
gpio_isr_handler_add(LOWV_DETECT_PIN, lowv_detect_isr, (void *)LOWV_DETECT_PIN);
|
|
<<<<<<< HEAD
|
|
gpio_isr_handler_add(SWITCH_INPUT_PIN, push_button_isr, (void *)SWITCH_INPUT_PIN);
|
|
=======
|
|
gpio_isr_handler_add(SWITCH_INPUT_PIN, push_button_isr, (void *)SWITCH_INPUT_PIN);*/
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
}
|
|
|
|
void port_init(void)
|
|
{
|
|
init_outputs();
|
|
<<<<<<< HEAD
|
|
init_inputs();
|
|
init_isrs();
|
|
|
|
gpio_deep_sleep_hold_dis();
|
|
=======
|
|
// init_inputs();
|
|
// init_isrs();
|
|
|
|
// gpio_deep_sleep_hold_dis();
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
/*rtc_gpio_init(LED_BLUE_PIN);
|
|
rtc_gpio_set_direction(LED_BLUE_PIN, RTC_GPIO_MODE_OUTPUT_ONLY);
|
|
rtc_gpio_pulldown_dis(LED_BLUE_PIN);
|
|
rtc_gpio_pullup_dis(LED_BLUE_PIN);
|
|
rtc_gpio_set_level(LED_BLUE_PIN, 1);*/
|
|
}
|
|
|
|
void port_red_led_on(void)
|
|
{
|
|
<<<<<<< HEAD
|
|
gpio_set_level(LED_RED_PIN, 1);
|
|
=======
|
|
gpio_set_level(LED_RED_PIN, 0);
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
red_led_status = 1;
|
|
}
|
|
void port_red_led_off(void)
|
|
{
|
|
<<<<<<< HEAD
|
|
gpio_set_level(LED_RED_PIN, 0);
|
|
red_led_status = 0;
|
|
}
|
|
|
|
=======
|
|
gpio_set_level(LED_RED_PIN, 1);
|
|
red_led_status = 0;
|
|
}
|
|
|
|
void port_green_led_off(void)
|
|
{
|
|
gpio_set_level(LED_GREEN_PIN, 1);
|
|
green_led_status = 0;
|
|
}
|
|
|
|
void port_green_led_on(void)
|
|
{
|
|
gpio_set_level(LED_GREEN_PIN, 0);
|
|
green_led_status = 1;
|
|
}
|
|
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
void port_red_led_toggle(void)
|
|
{
|
|
if(red_led_status)
|
|
{
|
|
port_red_led_off();
|
|
}
|
|
else
|
|
{
|
|
port_red_led_on();
|
|
}
|
|
}
|
|
|
|
bool port_red_led_is_on(void)
|
|
{
|
|
return red_led_status;
|
|
}
|
|
|
|
void port_blue_led_on(void)
|
|
{
|
|
<<<<<<< HEAD
|
|
gpio_set_level(LED_BLUE_PIN, 1);
|
|
=======
|
|
gpio_set_level(LED_BLUE_PIN, 0);
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
blue_led_status = 1;
|
|
}
|
|
void port_blue_led_off(void)
|
|
{
|
|
<<<<<<< HEAD
|
|
gpio_set_level(LED_BLUE_PIN, 0);
|
|
=======
|
|
gpio_set_level(LED_BLUE_PIN, 1);
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
blue_led_status = 0;
|
|
}
|
|
|
|
int port_is_pushbuttonNotPressed(void)
|
|
{
|
|
return gpio_get_level(SWITCH_INPUT_PIN);
|
|
}
|
|
|
|
void port_blue_led_toggle(void)
|
|
{
|
|
if(blue_led_status)
|
|
{
|
|
port_blue_led_off();
|
|
}
|
|
else
|
|
{
|
|
port_blue_led_on();
|
|
}
|
|
}
|
|
|
|
bool port_blue_led_is_on(void)
|
|
{
|
|
return blue_led_status;
|
|
}
|
|
|
|
<<<<<<< HEAD
|
|
void port_modem_assert_pwrkey(void)
|
|
=======
|
|
/*void port_modem_assert_pwrkey(void)
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
{
|
|
gpio_set_level(UD_RAD_PWRKEY_PIN, 1);
|
|
}
|
|
|
|
void port_modem_deassert_pwrkey(void)
|
|
{
|
|
gpio_set_level(UD_RAD_PWRKEY_PIN, 0);
|
|
<<<<<<< HEAD
|
|
}
|
|
=======
|
|
}*/
|
|
>>>>>>> 4ea13f8 (Added azuma wifi switch backup code)
|
|
|
|
int port_modem_is_on(void)
|
|
{
|
|
return gpio_get_level(RAD_STATUS_PIN);
|
|
}
|
|
|
|
int port_is_usb_connected(void)
|
|
{
|
|
return gpio_get_level(VUSB_DETECT_PIN);
|
|
}
|
|
|
|
int port_is_charging(void)
|
|
{
|
|
return gpio_get_level(USB_CHG_STATUS_PIN);
|
|
}
|
|
|
|
void port_vbatt_sense_enable(int en)
|
|
{
|
|
gpio_set_level(VBAT_SENSE_EN_PIN, en);
|
|
}
|
|
|
|
void port_accel_pwr_enable(int en)
|
|
{
|
|
gpio_set_level(ACCEL_PWN_PIN, en);
|
|
}
|
|
|
|
void port_light_sensor_enable(int en)
|
|
{
|
|
gpio_set_level(LIGHT_SENSOR_EN_PIN, en);
|
|
}
|
|
|
|
void port_modem_ldo_pin(uint8_t en)
|
|
{
|
|
gpio_set_level(MODEM_LDO_EN_PIN, en);
|
|
}
|
|
|
|
int port_usb_charge_status(void)
|
|
{
|
|
return gpio_get_level(USB_CHG_STATUS_PIN);
|
|
}
|
|
|
|
|
|
|