Changed logic
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
#include "mcu/mcu_hal.h"
|
#include "mcu/mcu_hal.h"
|
||||||
#include "ain.h"
|
#include "ain.h"
|
||||||
|
|
||||||
using namespace board;
|
using namespace bsp;
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
/**** Private constants ****/
|
/**** Private constants ****/
|
||||||
@@ -11,7 +11,7 @@ using namespace board;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
board::AnalogIn::AnalogIn(uint8_t adc_ch)
|
bsp::AnalogIn::AnalogIn(uint8_t adc_ch)
|
||||||
{
|
{
|
||||||
this->adc_ch = adc_ch;
|
this->adc_ch = adc_ch;
|
||||||
this->mul = DEF_AIN_MUL;
|
this->mul = DEF_AIN_MUL;
|
||||||
@@ -20,7 +20,7 @@ board::AnalogIn::AnalogIn(uint8_t adc_ch)
|
|||||||
this->last_read = 0;
|
this->last_read = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t board::AnalogIn::read(void)
|
uint16_t bsp::AnalogIn::read(void)
|
||||||
{
|
{
|
||||||
//Read ADC
|
//Read ADC
|
||||||
uint16_t raw = mcu::adc_read(this->adc_ch);
|
uint16_t raw = mcu::adc_read(this->adc_ch);
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace board {
|
namespace bsp {
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
static const uint8_t DEF_AIN_MUL = 215;
|
static const uint8_t DEF_AIN_MUL = 215;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "mcu/mcu_hal.h"
|
#include "mcu/mcu_hal.h"
|
||||||
#include "din.h"
|
#include "din.h"
|
||||||
|
|
||||||
using namespace board;
|
using namespace bsp;
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
/**** Private constants ****/
|
/**** Private constants ****/
|
||||||
@@ -11,7 +11,7 @@ using namespace board;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
board::DigitalIn::DigitalIn(uint8_t gpio_ch, uint8_t inverted, uint8_t init_value)
|
bsp::DigitalIn::DigitalIn(uint8_t gpio_ch, uint8_t inverted, uint8_t init_value)
|
||||||
{
|
{
|
||||||
this->gpio_ch = gpio_ch;
|
this->gpio_ch = gpio_ch;
|
||||||
this->invert = inverted;
|
this->invert = inverted;
|
||||||
@@ -20,12 +20,12 @@ board::DigitalIn::DigitalIn(uint8_t gpio_ch, uint8_t inverted, uint8_t init_valu
|
|||||||
else this->last_read = DIN_LOW;
|
else this->last_read = DIN_LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
board::DigitalIn::~DigitalIn(void)
|
bsp::DigitalIn::~DigitalIn(void)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t board::DigitalIn::read(void)
|
uint8_t bsp::DigitalIn::read(void)
|
||||||
{
|
{
|
||||||
uint8_t lvl = mcu::gpio_read(this->gpio_ch);
|
uint8_t lvl = mcu::gpio_read(this->gpio_ch);
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace board {
|
namespace bsp {
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
const uint8_t DIN_LOW = 0;
|
const uint8_t DIN_LOW = 0;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "mcu/mcu_hal.h"
|
#include "mcu/mcu_hal.h"
|
||||||
#include "dio.h"
|
#include "dio.h"
|
||||||
|
|
||||||
using namespace board;
|
using namespace bsp;
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
/**** Private constants ****/
|
/**** Private constants ****/
|
||||||
@@ -11,17 +11,17 @@ using namespace board;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
board::DigitalIO::DigitalIO(uint8_t gpio_ch, uint8_t init_value) : DigitalIn(gpio_ch, 0, init_value), DigitalOut(gpio_ch, 0)
|
bsp::DigitalIO::DigitalIO(uint8_t gpio_ch, uint8_t init_value) : DigitalIn(gpio_ch, 0, init_value), DigitalOut(gpio_ch, 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
board::DigitalIO::~DigitalIO(void)
|
bsp::DigitalIO::~DigitalIO(void)
|
||||||
{
|
{
|
||||||
this->write(DOUT_HIZ);
|
this->write(DOUT_HIZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t board::DigitalIO::is_io_match(void)
|
uint8_t bsp::DigitalIO::is_io_match(void)
|
||||||
{
|
{
|
||||||
if(this->last_set == DOUT_HIZ) return 1;
|
if(this->last_set == DOUT_HIZ) return 1;
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "din.h"
|
#include "din.h"
|
||||||
#include "dout.h"
|
#include "dout.h"
|
||||||
|
|
||||||
namespace board {
|
namespace bsp {
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
const int8_t DIO_LOW = 0;
|
const int8_t DIO_LOW = 0;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "mcu/mcu_hal.h"
|
#include "mcu/mcu_hal.h"
|
||||||
#include "dout.h"
|
#include "dout.h"
|
||||||
|
|
||||||
using namespace board;
|
using namespace bsp;
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
/**** Private constants ****/
|
/**** Private constants ****/
|
||||||
@@ -11,19 +11,19 @@ using namespace board;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
board::DigitalOut::DigitalOut(uint8_t gpio_ch, uint8_t inverted)
|
bsp::DigitalOut::DigitalOut(uint8_t gpio_ch, uint8_t inverted)
|
||||||
{
|
{
|
||||||
this->gpio_ch = gpio_ch;
|
this->gpio_ch = gpio_ch;
|
||||||
this->invert = inverted;
|
this->invert = inverted;
|
||||||
this->write(DOUT_HIZ);
|
this->write(DOUT_HIZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
board::DigitalOut::~DigitalOut(void)
|
bsp::DigitalOut::~DigitalOut(void)
|
||||||
{
|
{
|
||||||
this->write(DOUT_HIZ);
|
this->write(DOUT_HIZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
void board::DigitalOut::write(int8_t level)
|
void bsp::DigitalOut::write(int8_t level)
|
||||||
{
|
{
|
||||||
if(level > 0)
|
if(level > 0)
|
||||||
{
|
{
|
||||||
@@ -44,7 +44,7 @@ void board::DigitalOut::write(int8_t level)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t board::DigitalOut::get_set_level(void)
|
int8_t bsp::DigitalOut::get_set_level(void)
|
||||||
{
|
{
|
||||||
return this->last_set;
|
return this->last_set;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace board {
|
namespace bsp {
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
const int8_t DOUT_LOW = 0;
|
const int8_t DOUT_LOW = 0;
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "mcu/mcu_hal.h"
|
#include "mcu/mcu_hal.h"
|
||||||
#include "halfbridge.h"
|
#include "halfbridge.h"
|
||||||
|
|
||||||
using namespace board;
|
using namespace bsp;
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
/**** Private constants ****/
|
/**** Private constants ****/
|
||||||
@@ -11,7 +11,7 @@ using namespace board;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
board::Hafbridge::Hafbridge(uint8_t hs_pwm_ch, uint8_t ls_gpio_ch, uint8_t max_dc)
|
bsp::Hafbridge::Hafbridge(uint8_t hs_pwm_ch, uint8_t ls_gpio_ch, uint8_t max_dc)
|
||||||
{
|
{
|
||||||
this->pwm_ch = hs_pwm_ch;
|
this->pwm_ch = hs_pwm_ch;
|
||||||
this->gpio_ch = ls_gpio_ch;
|
this->gpio_ch = ls_gpio_ch;
|
||||||
@@ -23,13 +23,13 @@ board::Hafbridge::Hafbridge(uint8_t hs_pwm_ch, uint8_t ls_gpio_ch, uint8_t max_d
|
|||||||
this->disable();
|
this->disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
board::Hafbridge::~Hafbridge(void)
|
bsp::Hafbridge::~Hafbridge(void)
|
||||||
{
|
{
|
||||||
this->last_duty = 0;
|
this->last_duty = 0;
|
||||||
this->disable();
|
this->disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void board::Hafbridge::write(uint16_t dividend)
|
void bsp::Hafbridge::write(uint16_t dividend)
|
||||||
{
|
{
|
||||||
// Limit duty
|
// Limit duty
|
||||||
if(dividend > this->max_dc) dividend = this->max_dc;
|
if(dividend > this->max_dc) dividend = this->max_dc;
|
||||||
@@ -41,32 +41,32 @@ void board::Hafbridge::write(uint16_t dividend)
|
|||||||
mcu::pwm_write(this->pwm_ch, dividend);
|
mcu::pwm_write(this->pwm_ch, dividend);
|
||||||
}
|
}
|
||||||
|
|
||||||
void board::Hafbridge::write(uint8_t percent)
|
void bsp::Hafbridge::write(uint8_t percent)
|
||||||
{
|
{
|
||||||
// Convert to dividend/0xFFFF
|
// Convert to dividend/0xFFFF
|
||||||
this->write(util::percent_to_16b(percent));
|
this->write(util::percent_to_16b(percent));
|
||||||
}
|
}
|
||||||
|
|
||||||
void board::Hafbridge::enable(void)
|
void bsp::Hafbridge::enable(void)
|
||||||
{
|
{
|
||||||
mcu::gpio_write(this->gpio_ch, mcu::LEVEL_HIGH);
|
mcu::gpio_write(this->gpio_ch, mcu::LEVEL_HIGH);
|
||||||
this->enabled = 1;
|
this->enabled = 1;
|
||||||
this->write(this->last_duty);
|
this->write(this->last_duty);
|
||||||
}
|
}
|
||||||
|
|
||||||
void board::Hafbridge::disable(void)
|
void bsp::Hafbridge::disable(void)
|
||||||
{
|
{
|
||||||
mcu::pwm_write(this->pwm_ch, 0);
|
mcu::pwm_write(this->pwm_ch, 0);
|
||||||
mcu::gpio_write(this->gpio_ch, mcu::LEVEL_LOW);
|
mcu::gpio_write(this->gpio_ch, mcu::LEVEL_LOW);
|
||||||
this->enabled = 0;
|
this->enabled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t board::Hafbridge::get_set_duty(void)
|
uint8_t bsp::Hafbridge::get_set_duty(void)
|
||||||
{
|
{
|
||||||
return this->last_duty;
|
return this->last_duty;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t board::Hafbridge::is_enabled(void)
|
uint8_t bsp::Hafbridge::is_enabled(void)
|
||||||
{
|
{
|
||||||
return this->enabled;
|
return this->enabled;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace board {
|
namespace bsp {
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
class Hafbridge
|
class Hafbridge
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "mcu/mcu_hal.h"
|
#include "mcu/mcu_hal.h"
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
|
|
||||||
using namespace board;
|
using namespace bsp;
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
/**** Private constants ****/
|
/**** Private constants ****/
|
||||||
@@ -11,18 +11,18 @@ using namespace board;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
board::PWMout::PWMout(uint8_t pwm_ch)
|
bsp::PWMout::PWMout(uint8_t pwm_ch)
|
||||||
{
|
{
|
||||||
this->pwm_ch = pwm_ch;
|
this->pwm_ch = pwm_ch;
|
||||||
this->write(0);
|
this->write(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
board::PWMout::~PWMout(void)
|
bsp::PWMout::~PWMout(void)
|
||||||
{
|
{
|
||||||
this->write(0);
|
this->write(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void board::PWMout::write(uint8_t duty)
|
void bsp::PWMout::write(uint8_t duty)
|
||||||
{
|
{
|
||||||
// Convert percent to 16b duty cycle
|
// Convert percent to 16b duty cycle
|
||||||
uint16_t dc = util::percent_to_16b(duty);
|
uint16_t dc = util::percent_to_16b(duty);
|
||||||
@@ -32,7 +32,7 @@ void board::PWMout::write(uint8_t duty)
|
|||||||
this->last_duty = duty;
|
this->last_duty = duty;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t board::PWMout::get_set_duty(void)
|
uint8_t bsp::PWMout::get_set_duty(void)
|
||||||
{
|
{
|
||||||
return this->last_duty;
|
return this->last_duty;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace board {
|
namespace bsp {
|
||||||
|
|
||||||
/**** Public definitions ****/
|
/**** Public definitions ****/
|
||||||
class PWMout
|
class PWMout
|
||||||
@@ -10,12 +10,12 @@ using namespace hw;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
hw::Button::Button(board::DigitalIn* din_ch, uint8_t act_lvl, uint8_t dbnc_lim, uint8_t init_state)
|
hw::Button::Button(bsp::DigitalIn* din_ch, uint8_t act_lvl, uint8_t dbnc_lim, uint8_t init_state)
|
||||||
{
|
{
|
||||||
this->din_ch = din_ch;
|
this->din_ch = din_ch;
|
||||||
|
|
||||||
if(act_lvl) this->act_lvl = board::DIN_HIGH;
|
if(act_lvl) this->act_lvl = bsp::DIN_HIGH;
|
||||||
else this->act_lvl = board::DIN_LOW;
|
else this->act_lvl = bsp::DIN_LOW;
|
||||||
|
|
||||||
this->dbnc_cnter = 0;
|
this->dbnc_cnter = 0;
|
||||||
this->dbnc_lim = dbnc_lim;
|
this->dbnc_lim = dbnc_lim;
|
||||||
@@ -32,10 +32,10 @@ hw::Button::~Button(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t hw::Button::read(void)
|
uint8_t hw::Button::update(void)
|
||||||
{
|
{
|
||||||
// Read din level
|
// Read din level
|
||||||
uint8_t lvl = this->din_ch->read();
|
uint8_t lvl = this->din_ch->last_read;
|
||||||
|
|
||||||
// Increase state counter
|
// Increase state counter
|
||||||
this->time = util::sat_add(this->time, 1);
|
this->time = util::sat_add(this->time, 1);
|
||||||
@@ -60,7 +60,7 @@ uint8_t hw::Button::read(void)
|
|||||||
return this->state;
|
return this->state;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t hw::Button::force_read(void)
|
uint8_t hw::Button::force_update(void)
|
||||||
{
|
{
|
||||||
// Read din level
|
// Read din level
|
||||||
uint8_t lvl = this->din_ch->read();
|
uint8_t lvl = this->din_ch->read();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../board/din.h"
|
#include "../bsp/din.h"
|
||||||
|
|
||||||
namespace hw {
|
namespace hw {
|
||||||
|
|
||||||
@@ -14,12 +14,12 @@ const uint8_t BUTTON_ON = 1;
|
|||||||
class Button
|
class Button
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
board::DigitalIn* din_ch;
|
bsp::DigitalIn* din_ch;
|
||||||
uint8_t act_lvl;
|
uint8_t act_lvl;
|
||||||
uint8_t dbnc_cnter;
|
uint8_t dbnc_cnter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Button(board::DigitalIn* din_ch, uint8_t act_lvl, uint8_t dbnc_lim, uint8_t init_state);
|
Button(bsp::DigitalIn* din_ch, uint8_t act_lvl, uint8_t dbnc_lim, uint8_t init_state);
|
||||||
~Button(void);
|
~Button(void);
|
||||||
|
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
@@ -27,8 +27,8 @@ class Button
|
|||||||
uint8_t dbnc_lim;
|
uint8_t dbnc_lim;
|
||||||
uint8_t is_new;
|
uint8_t is_new;
|
||||||
|
|
||||||
uint8_t read(void);
|
uint8_t update(void);
|
||||||
uint8_t force_read(void);
|
uint8_t force_update(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
/**** Public function declarations ****/
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ using namespace hw;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
hw::CVoutput::CVoutput(board::Hafbridge* hbridge)
|
hw::CVoutput::CVoutput(bsp::Hafbridge* hbridge, bsp::AnalogIn* supply_u)
|
||||||
{
|
{
|
||||||
this->hbridge = hbridge;
|
this->hbridge = hbridge;
|
||||||
|
this->supply = supply_u;
|
||||||
this->target = 0;
|
this->target = 0;
|
||||||
this->min_out = 0;
|
this->min_out = 0;
|
||||||
this->hbridge->disable();
|
this->hbridge->disable();
|
||||||
@@ -20,18 +21,18 @@ hw::CVoutput::CVoutput(board::Hafbridge* hbridge)
|
|||||||
|
|
||||||
hw::CVoutput::~CVoutput(void)
|
hw::CVoutput::~CVoutput(void)
|
||||||
{
|
{
|
||||||
this->hbridge->write((uint16_t)0);
|
this->hbridge->write((uint16_t)0x0000);
|
||||||
this->hbridge->disable();
|
this->hbridge->disable();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hw::CVoutput::update(uint16_t supply_mv)
|
void hw::CVoutput::update(void)
|
||||||
{
|
{
|
||||||
// Check target
|
// Check target
|
||||||
if((this->target < this->min_out)&&(this->target > 0)) this->target = this->min_out;
|
if((this->target < this->min_out)&&(this->target > 0)) this->target = this->min_out;
|
||||||
|
|
||||||
// Set output
|
// Set output
|
||||||
this->hbridge->write(util::sat_ratio(this->target, supply_mv));
|
this->hbridge->write(util::sat_ratio(this->target, this->supply->last_read));
|
||||||
}
|
}
|
||||||
|
|
||||||
void hw::CVoutput::enable(void)
|
void hw::CVoutput::enable(void)
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../board/halfbridge.h"
|
#include "../bsp/ain.h"
|
||||||
|
#include "../bsp/halfbridge.h"
|
||||||
|
|
||||||
namespace hw {
|
namespace hw {
|
||||||
|
|
||||||
@@ -12,16 +13,17 @@ namespace hw {
|
|||||||
class CVoutput
|
class CVoutput
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
board::Hafbridge* hbridge;
|
bsp::Hafbridge* hbridge;
|
||||||
|
bsp::AnalogIn* supply;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CVoutput(board::Hafbridge* hbridge);
|
CVoutput(bsp::Hafbridge* hbridge, bsp::AnalogIn* supply_u);
|
||||||
~CVoutput(void);
|
~CVoutput(void);
|
||||||
|
|
||||||
uint16_t target;
|
uint16_t target;
|
||||||
uint16_t min_out;
|
uint16_t min_out;
|
||||||
|
|
||||||
void update(uint16_t supply_mv);
|
void update(void);
|
||||||
void enable(void);
|
void enable(void);
|
||||||
void disable(void);
|
void disable(void);
|
||||||
uint8_t is_enabled(void);
|
uint8_t is_enabled(void);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ static uint8_t img_gen_dot20(uint8_t percent);
|
|||||||
static uint8_t img_gen_bar(uint8_t percent);
|
static uint8_t img_gen_bar(uint8_t percent);
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
hw::DisplayLed::DisplayLed(board::DigitalOut* led0, board::DigitalOut* led1, board::DigitalOut* led2, board::DigitalOut* led3, board::DigitalOut* led4, board::DigitalOut* led5, board::PWMout* common)
|
hw::DisplayLed::DisplayLed(bsp::DigitalOut* led0, bsp::DigitalOut* led1, bsp::DigitalOut* led2, bsp::DigitalOut* led3, bsp::DigitalOut* led4, bsp::DigitalOut* led5, bsp::PWMout* common)
|
||||||
{
|
{
|
||||||
this->led0 = led0;
|
this->led0 = led0;
|
||||||
this->led1 = led1;
|
this->led1 = led1;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../board/dout.h"
|
#include "../bsp/dout.h"
|
||||||
#include "../board/pwm.h"
|
#include "../bsp/pwm.h"
|
||||||
|
|
||||||
namespace hw {
|
namespace hw {
|
||||||
|
|
||||||
@@ -13,13 +13,13 @@ namespace hw {
|
|||||||
class DisplayLed
|
class DisplayLed
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
board::DigitalOut* led0;
|
bsp::DigitalOut* led0;
|
||||||
board::DigitalOut* led1;
|
bsp::DigitalOut* led1;
|
||||||
board::DigitalOut* led2;
|
bsp::DigitalOut* led2;
|
||||||
board::DigitalOut* led3;
|
bsp::DigitalOut* led3;
|
||||||
board::DigitalOut* led4;
|
bsp::DigitalOut* led4;
|
||||||
board::DigitalOut* led5;
|
bsp::DigitalOut* led5;
|
||||||
board::PWMout* common;
|
bsp::PWMout* common;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -28,7 +28,7 @@ class DisplayLed
|
|||||||
LED_DSP_BAR
|
LED_DSP_BAR
|
||||||
} style_t;
|
} style_t;
|
||||||
|
|
||||||
DisplayLed(board::DigitalOut* led0, board::DigitalOut* led1, board::DigitalOut* led2, board::DigitalOut* led3, board::DigitalOut* led4, board::DigitalOut* led5, board::PWMout* common);
|
DisplayLed(bsp::DigitalOut* led0, bsp::DigitalOut* led1, bsp::DigitalOut* led2, bsp::DigitalOut* led3, bsp::DigitalOut* led4, bsp::DigitalOut* led5, bsp::PWMout* common);
|
||||||
~DisplayLed(void);
|
~DisplayLed(void);
|
||||||
|
|
||||||
void show_percent(uint8_t percent, style_t style);
|
void show_percent(uint8_t percent, style_t style);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ using namespace hw;
|
|||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
hw::Potentiometer::Potentiometer(board::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone)
|
hw::Potentiometer::Potentiometer(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone)
|
||||||
{
|
{
|
||||||
this->ain_ch = ain_ch;
|
this->ain_ch = ain_ch;
|
||||||
this->low_deadzone = low_deadzone;
|
this->low_deadzone = low_deadzone;
|
||||||
@@ -24,11 +24,8 @@ hw::Potentiometer::~Potentiometer(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t hw::Potentiometer::read(void)
|
uint8_t hw::Potentiometer::update(void)
|
||||||
{
|
{
|
||||||
// Update input
|
|
||||||
this->ain_ch->read();
|
|
||||||
|
|
||||||
// Calculate percent
|
// Calculate percent
|
||||||
this->percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100);
|
this->percent = util::interpolate(this->ain_ch->last_read, this->low_deadzone, this->high_deadzone, 0, 100);
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "../board/ain.h"
|
#include "../bsp/ain.h"
|
||||||
|
|
||||||
namespace hw {
|
namespace hw {
|
||||||
|
|
||||||
@@ -12,17 +12,17 @@ namespace hw {
|
|||||||
class Potentiometer
|
class Potentiometer
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
board::AnalogIn* ain_ch;
|
bsp::AnalogIn* ain_ch;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Potentiometer(board::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone);
|
Potentiometer(bsp::AnalogIn* ain_ch, uint16_t low_deadzone, uint16_t high_deadzone);
|
||||||
~Potentiometer(void);
|
~Potentiometer(void);
|
||||||
|
|
||||||
uint16_t low_deadzone;
|
uint16_t low_deadzone;
|
||||||
uint16_t high_deadzone;
|
uint16_t high_deadzone;
|
||||||
uint8_t percent;
|
uint8_t percent;
|
||||||
|
|
||||||
uint8_t read(void);
|
uint8_t update(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**** Public function declarations ****/
|
/**** Public function declarations ****/
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
/**** Includes ****/
|
/**** Includes ****/
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
#include "board/mcu/mcu_hal.h"
|
#include "bsp/mcu/mcu_hal.h"
|
||||||
#include "board/ain.h"
|
#include "bsp/ain.h"
|
||||||
#include "board/din.h"
|
#include "bsp/din.h"
|
||||||
#include "board/dout.h"
|
#include "bsp/dout.h"
|
||||||
#include "board/dio.h"
|
#include "bsp/dio.h"
|
||||||
#include "board/halfbridge.h"
|
#include "bsp/halfbridge.h"
|
||||||
#include "board/pwm.h"
|
#include "bsp/pwm.h"
|
||||||
|
|
||||||
#include "hw/button.h"
|
#include "hw/button.h"
|
||||||
#include "hw/potentiometer.h"
|
#include "hw/potentiometer.h"
|
||||||
@@ -15,63 +15,49 @@
|
|||||||
#include "hw/cv_output.h"
|
#include "hw/cv_output.h"
|
||||||
|
|
||||||
/**** Private definitions ****/
|
/**** Private definitions ****/
|
||||||
static board::AnalogIn dccd_i(mcu::ADC0);
|
/**** Private constants ****/
|
||||||
static board::AnalogIn dccd_u(mcu::ADC1);
|
/**** Private variables ****/
|
||||||
static board::AnalogIn bat_u(mcu::ADC2);
|
static bsp::AnalogIn dccd_i(mcu::ADC0);
|
||||||
static board::AnalogIn bat_i(mcu::ADC3);
|
static bsp::AnalogIn dccd_u(mcu::ADC1);
|
||||||
|
static bsp::AnalogIn bat_u(mcu::ADC2);
|
||||||
|
static bsp::AnalogIn bat_i(mcu::ADC3);
|
||||||
|
static bsp::Hafbridge hbridge(mcu::PWM0, mcu::GPIO15, 95);
|
||||||
|
static bsp::AnalogIn ain1(mcu::ADC5); // mode
|
||||||
|
static bsp::AnalogIn ain2(mcu::ADC4); // pot
|
||||||
|
static bsp::DigitalIn din1(mcu::GPIO0, 0, bsp::DIN_HIGH); //mode
|
||||||
|
static bsp::DigitalIn din2(mcu::GPIO1, 0, bsp::DIN_HIGH); //pot
|
||||||
|
static bsp::DigitalIn din3(mcu::GPIO2, 0, bsp::DIN_HIGH); //down
|
||||||
|
static bsp::DigitalIn din4(mcu::GPIO3, 0, bsp::DIN_HIGH); //up
|
||||||
|
static bsp::DigitalIn hvdin1(mcu::GPIO4, 1, bsp::DIN_LOW); //dimm
|
||||||
|
static bsp::DigitalIn hvdin2(mcu::GPIO5, 1, bsp::DIN_LOW); //brakes
|
||||||
|
static bsp::DigitalIn hvdin3(mcu::GPIO6, 1, bsp::DIN_LOW); //hbrake
|
||||||
|
static bsp::DigitalIO hvdin3_pull(mcu::GPIO7, bsp::DIN_HIGH); //hbrake pull
|
||||||
|
static bsp::DigitalOut odout1(mcu::GPIO9, 1);
|
||||||
|
static bsp::DigitalOut odout2(mcu::GPIO10, 1);
|
||||||
|
static bsp::DigitalOut odout3(mcu::GPIO11, 1);
|
||||||
|
static bsp::DigitalOut odout4(mcu::GPIO12, 1);
|
||||||
|
static bsp::DigitalOut odout5(mcu::GPIO13, 1);
|
||||||
|
static bsp::DigitalOut odout6(mcu::GPIO14, 1);
|
||||||
|
static bsp::PWMout od_pwm(mcu::PWM1);
|
||||||
|
|
||||||
static board::Hafbridge hbridge(mcu::PWM0, mcu::GPIO15, 95);
|
static hw::Button btn_mode(&din1, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||||
|
static hw::Button btn_up(&din4, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||||
|
static hw::Button btn_down(&din3, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||||
|
|
||||||
static board::AnalogIn ain1(mcu::ADC5); // mode
|
static hw::Button sw_dimm(&hvdin1, bsp::DIN_HIGH, 10, hw::BUTTON_OFF);
|
||||||
static board::AnalogIn ain2(mcu::ADC4); // pot
|
static hw::Button sw_brakes(&hvdin2, bsp::DIN_HIGH, 10, hw::BUTTON_OFF);
|
||||||
|
static hw::Button sw_hbrake(&hvdin3, bsp::DIN_LOW, 10, hw::BUTTON_OFF);
|
||||||
static board::DigitalIn din1(mcu::GPIO0, 0, board::DIN_HIGH); //mode
|
|
||||||
static board::DigitalIn din2(mcu::GPIO1, 0, board::DIN_HIGH); //pot
|
|
||||||
static board::DigitalIn din3(mcu::GPIO2, 0, board::DIN_HIGH); //down
|
|
||||||
static board::DigitalIn din4(mcu::GPIO3, 0, board::DIN_HIGH); //up
|
|
||||||
|
|
||||||
static board::DigitalIn hvdin1(mcu::GPIO4, 1, board::DIN_LOW); //dimm
|
|
||||||
static board::DigitalIn hvdin2(mcu::GPIO5, 1, board::DIN_LOW); //brakes
|
|
||||||
static board::DigitalIn hvdin3(mcu::GPIO6, 1, board::DIN_LOW); //hbrake
|
|
||||||
static board::DigitalIO hvdin3_pull(mcu::GPIO7, board::DIN_HIGH); //hbrake pull
|
|
||||||
|
|
||||||
static board::DigitalOut odout1(mcu::GPIO9, 1);
|
|
||||||
static board::DigitalOut odout2(mcu::GPIO10, 1);
|
|
||||||
static board::DigitalOut odout3(mcu::GPIO11, 1);
|
|
||||||
static board::DigitalOut odout4(mcu::GPIO12, 1);
|
|
||||||
static board::DigitalOut odout5(mcu::GPIO13, 1);
|
|
||||||
static board::DigitalOut odout6(mcu::GPIO14, 1);
|
|
||||||
|
|
||||||
static board::PWMout od_pwm(mcu::PWM1);
|
|
||||||
|
|
||||||
static hw::Button btn_mode(&din1, board::DIN_LOW, 10, hw::BUTTON_OFF);
|
|
||||||
static hw::Button btn_up(&din4, board::DIN_LOW, 10, hw::BUTTON_OFF);
|
|
||||||
static hw::Button btn_down(&din3, board::DIN_LOW, 10, hw::BUTTON_OFF);
|
|
||||||
|
|
||||||
static hw::Button sw_dimm(&hvdin1, board::DIN_HIGH, 10, hw::BUTTON_OFF);
|
|
||||||
static hw::Button sw_brakes(&hvdin2, board::DIN_HIGH, 10, hw::BUTTON_OFF);
|
|
||||||
static hw::Button sw_hbrake(&hvdin3, board::DIN_LOW, 10, hw::BUTTON_OFF);
|
|
||||||
|
|
||||||
static hw::Potentiometer pot(&ain2, 500, 4500);
|
static hw::Potentiometer pot(&ain2, 500, 4500);
|
||||||
|
|
||||||
static hw::DisplayLed display(&odout1, &odout2, &odout3, &odout4, &odout5, &odout6, &od_pwm);
|
static hw::DisplayLed display(&odout1, &odout2, &odout3, &odout4, &odout5, &odout6, &od_pwm);
|
||||||
|
|
||||||
static hw::CVoutput cvout(&hbridge);
|
static hw::CVoutput cvout(&hbridge, &bat_u);
|
||||||
|
|
||||||
/**** Private constants ****/
|
|
||||||
/**** Private variables ****/
|
|
||||||
/**** Private function declarations ****/
|
/**** Private function declarations ****/
|
||||||
static void board_setup(void);
|
|
||||||
|
|
||||||
/**** Public function definitions ****/
|
/**** Public function definitions ****/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
board_setup();
|
|
||||||
|
|
||||||
cvout.target = 0;
|
|
||||||
cvout.min_out = 500;
|
|
||||||
cvout.enable();
|
|
||||||
|
|
||||||
// Super loop
|
// Super loop
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
@@ -83,35 +69,3 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**** Private function definitions ***/
|
/**** Private function definitions ***/
|
||||||
static void board_setup(void)
|
|
||||||
{
|
|
||||||
mcu::startupCfg_t mcu_cfg;
|
|
||||||
mcu_cfg.adc_clk = mcu::ADC_DIV2;
|
|
||||||
mcu_cfg.pwm_clk = mcu::TIM_DIV1;
|
|
||||||
mcu_cfg.pwm_top = 200;
|
|
||||||
mcu_cfg.pwm_ch1_en = 1;
|
|
||||||
|
|
||||||
mcu::startup(&mcu_cfg);
|
|
||||||
|
|
||||||
dccd_i.mul = 215;
|
|
||||||
dccd_i.div = 22;
|
|
||||||
dccd_i.offset = 0;
|
|
||||||
dccd_i.last_read = 0;
|
|
||||||
|
|
||||||
dccd_u.mul = 20;
|
|
||||||
dccd_u.div = 1;
|
|
||||||
dccd_u.offset = 0;
|
|
||||||
dccd_u.last_read = 0;
|
|
||||||
|
|
||||||
bat_u.mul = 20;
|
|
||||||
bat_u.div = 1;
|
|
||||||
bat_u.offset = 0;
|
|
||||||
bat_u.last_read = 12000;
|
|
||||||
|
|
||||||
bat_i.mul = 235;
|
|
||||||
bat_i.div = 6;
|
|
||||||
bat_i.offset = 0;
|
|
||||||
bat_i.last_read = 0;
|
|
||||||
|
|
||||||
od_pwm.write(100);
|
|
||||||
}
|
|
||||||
@@ -153,46 +153,46 @@
|
|||||||
</ToolchainSettings>
|
</ToolchainSettings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="board\ain.cpp">
|
<Compile Include="bsp\ain.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\ain.h">
|
<Compile Include="bsp\ain.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\din.cpp">
|
<Compile Include="bsp\din.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\din.h">
|
<Compile Include="bsp\din.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\dio.cpp">
|
<Compile Include="bsp\dio.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\dio.h">
|
<Compile Include="bsp\dio.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\halfbridge.cpp">
|
<Compile Include="bsp\halfbridge.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\halfbridge.h">
|
<Compile Include="bsp\halfbridge.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\mcu\mcu_hal.h">
|
<Compile Include="bsp\mcu\mcu_hal.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\mcu\mcu_hal_r8.cpp">
|
<Compile Include="bsp\mcu\mcu_hal_r8.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\dout.cpp">
|
<Compile Include="bsp\dout.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\dout.h">
|
<Compile Include="bsp\dout.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\pwm.cpp">
|
<Compile Include="bsp\pwm.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="board\pwm.h">
|
<Compile Include="bsp\pwm.h">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="hw\button.cpp">
|
<Compile Include="hw\button.cpp">
|
||||||
@@ -236,8 +236,8 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="board" />
|
<Folder Include="bsp" />
|
||||||
<Folder Include="board\mcu" />
|
<Folder Include="bsp\mcu" />
|
||||||
<Folder Include="hw" />
|
<Folder Include="hw" />
|
||||||
<Folder Include="utils" />
|
<Folder Include="utils" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user