/*
 * pwm.h
 *
 *  Created on: 16 Jun 2020
 *      Author: tm
 */

#ifndef MPHOX_PWM_H_
#define MPHOX_PWM_H_

#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <ctype.h>


#define ST_PWM_IDLE    0
#define ST_PWM_LO      1
#define ST_PWM_HI      2
#define ST_PWM_PERMIL_LO   3
#define ST_PWM_PERMIL_HI   4


struct pwmDriver
{
    uint32_t        state;      // PG1,PG3 0=off, 1=on, 2=permil, 3=hiZ(future)
    uint32_t        cnt;        // count variable for pwm switching
    uint32_t        gpio;       // variable holding state of gpio
    uint32_t        delta;
    uint32_t        prevVal;    // previous value (speculative need)
    uint32_t        period;     // 1msec hardcoded in first implementation. inverse of frequency.
    uint32_t        permil;     // 0 to 999
};

void pwm_init(void);

int pwm_stateMachine(int pwmState);
void pwmSoln_stop(unsigned int val);
void pwmSoln_set(unsigned int pwmVal);

#endif /* MPHOX_PWM_H_ */
