/*
 * power.h
 *
 *  Created on: Apr 19, 2021
 *      Author: Thom Maughan
 */

#ifndef PHFETSOS_BOARD_UTIL_H_
#define PHFETSOS_BOARD_UTIL_H_

#include <stdint.h>

struct watchDog
{
    uint32_t tickStart;     //for timing how long between 'wdog_pet' calls.
    uint32_t tickDelta;
    uint32_t tickTot;
    uint32_t tickLongest;
    uint32_t bitten;        //came out of reset and wdog_ff was set.

};

void sys_rts(uint32_t state);
uint32_t sys_cts(void);

// returns 1 on success
int wdog_init(void);
// returns 1 on success
int wdog_pet(void);
// returns 1 on success
int wdog_resetMon(void);

// returns 1 if the ext watchdog has tripped
// returns 0 if the ext watchdog has not tripped
int wdog_readMon(void);

int uSD_present(void);
void crash_phfetsos(void);

void led_init(void);
void led_red(int state);
void led_red_toggle(void);
void led_red_on(void);
void led_red_off(void);
void led_green(int state);
void led_green_toggle(void);
void led_green_on(void);
void led_green_off(void);

void led_power_on(void);        // green
void led_power_off(void);
void led_sampling_on(void);
void led_sampling_off(void);

void profile_on(int target);
void profile_off(int target);
void profile2_on(int target);
void profile2_off(int target);
void profile2_toggle(int target);

void pwr_env_mon_on(void);
void pwr_env_mon_off(void);      // Turn off Load switch for ENV monitoring
void pwr_vbat_mon_on(void);    // Turn on VBat monitoring
void pwr_vbat_mon_off(void);   // Turn off VBat monitoring
void pwr_iso_on(void);         // Iso-power Off
void pwr_iso_off(void);        // Iso-power Off
void pwr_uSD_on(void);
void pwr_uSD_off(void);
void pwr_flash_off(void);
void pwr_flash_on(void);

void pwr_aux_pwr1_on(void);     // MPHOX j12
void pwr_aux_pwr1_off(void);
void pwr_aux_pwr2_on(void);     // MPHOX J13
void pwr_aux_pwr2_off(void);
void pwr_aux_pwr3_on(void);     // on COMM-PWR port J14
void pwr_aux_pwr3_off(void);
void pwr_soln_on(void);
void pwr_soln_off(void);
void solenoid_hit(void);
void solenoid_hold(unsigned int pwmVal);
void solenoid_off(void);
void solenoid_on(void);

void pwr_pump_on(void);
void pwr_pump_off(void);

void pump_on(void);     // same as pwr_aux_pwr1_on()
void pump_off(void);
void pump1_on(void);     // same as pwr_aux_pwr1_on()
void pump1_off(void);
void pump2_on(void);     // same as pwr_soln_on
void pump2_off(void);       // same as pwr_soln_off
void pressure_on(void);
void pressure_off(void);

void console_on(void);
void console_off(void);

void pwr_ctd_on(void);
void pwr_ctd_off(void);

void PORTXXX_on(void);      // gpio power control for the 'non-existent on existing boards' port formerly known as Aux2 on the SEAPHOX
void PORTXXX_off(void);

#endif /* POWER_H_ */
