mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 10:45:11 +03:00
Release code
This commit is contained in:
parent
6cb98bb7ed
commit
81e58130de
@ -0,0 +1,75 @@
|
|||||||
|
A usefull thing made of chineese FX3U clone
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
Works over RS-232 (default: 115200, 8N1) or CAN (default 250000 baud).
|
||||||
|
|
||||||
|
You can see pinout table in file `hardware.c`.
|
||||||
|
|
||||||
|
## Serial protocol (each string ends with '\n').
|
||||||
|
|
||||||
|
```
|
||||||
|
commands format: parameter[number][=setter]
|
||||||
|
parameter [CAN idx] - help
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
CAN bus commands:
|
||||||
|
canbuserr - print all CAN bus errors (a lot of if not connected)
|
||||||
|
cansniff - switch CAN sniffer mode
|
||||||
|
|
||||||
|
Configuration:
|
||||||
|
bounce [14] - set/get anti-bounce timeout (ms, max: 1000)
|
||||||
|
canid [6] - set both (in/out) CAN ID / get in CAN ID
|
||||||
|
canidin [7] - get/set input CAN ID
|
||||||
|
canidout [8] - get/set output CAN ID
|
||||||
|
canspeed [5] - get/set CAN speed (bps)
|
||||||
|
dumpconf - dump current configuration
|
||||||
|
eraseflash [10] - erase all flash storage
|
||||||
|
saveconf [9] - save configuration
|
||||||
|
usartspeed [15] - get/set USART1 speed
|
||||||
|
|
||||||
|
IN/OUT:
|
||||||
|
adc [4] - get raw ADC values for given channel
|
||||||
|
esw [12] - anti-bounce read inputs
|
||||||
|
eswnow [13] - read current inputs' state
|
||||||
|
led [16] - work with onboard LED
|
||||||
|
relay [11] - get/set relay state (0 - off, 1 - on)
|
||||||
|
|
||||||
|
Other commands:
|
||||||
|
mcutemp [3] - get MCU temperature (*10degrC)
|
||||||
|
reset [1] - reset MCU
|
||||||
|
s - send CAN message: ID 0..8 data bytes
|
||||||
|
time [2] - get/set time (1ms, 32bit)
|
||||||
|
wdtest - test watchdog
|
||||||
|
error=badcmd
|
||||||
|
```
|
||||||
|
|
||||||
|
Value in square brackets is CAN bus command code.
|
||||||
|
|
||||||
|
## CAN bus protocol
|
||||||
|
|
||||||
|
All data in little-endian format!
|
||||||
|
|
||||||
|
BIT - MEANING
|
||||||
|
|
||||||
|
0, 1 - (uint16_t) - command code (value in square brackets upper);
|
||||||
|
|
||||||
|
2 - (uint8_t) - parameter number (e.g. ADC channel or X/Y channel number), 0..127 [ORed with 0x80 for setter];
|
||||||
|
|
||||||
|
3 - (uint8_t) - error code (only when device answers for requests);
|
||||||
|
|
||||||
|
4..7 - (int32_t) - data.
|
||||||
|
|
||||||
|
### CAN bus error codes
|
||||||
|
|
||||||
|
0 - `ERR_OK` - all OK,
|
||||||
|
|
||||||
|
1 - `ERR_BADPAR` - parameter is wrong,
|
||||||
|
|
||||||
|
2 - `ERR_BADVAL` - value is wrong (e.g. out of range),
|
||||||
|
|
||||||
|
3 - `ERR_WRONGLEN` - wrong message length (for setter or for obligatory parameter number),
|
||||||
|
|
||||||
|
4 - `ERR_BADCMD` - unknown command code,
|
||||||
|
|
||||||
|
5 - `ERR_CANTRUN` - can't run given command due to bad parameters or other reason.
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ void adc_setup(){
|
|||||||
ADC1->SMPR1 = ADC_SMPR1_SMP16 | ADC_SMPR1_SMP17;
|
ADC1->SMPR1 = ADC_SMPR1_SMP16 | ADC_SMPR1_SMP17;
|
||||||
// sequence order: 1[0]->3[1]->14[2]->15[3]->10[4]->11[5] -> 16[tsen] -> 17[vdd]
|
// sequence order: 1[0]->3[1]->14[2]->15[3]->10[4]->11[5] -> 16[tsen] -> 17[vdd]
|
||||||
ADC1->SQR3 = (1 << 0) | (3<<5) | (14 << 10) | (15 << 15) | (10 << 20) | (11 < 25);
|
ADC1->SQR3 = (1 << 0) | (3<<5) | (14 << 10) | (15 << 15) | (10 << 20) | (11 < 25);
|
||||||
ADC1->SQR2 = (16 << 0) | (17 << 5);
|
ADC1->SQR2 = (12 << 0) | (13 << 5) | (16 << 10) | (17 << 15);
|
||||||
ADC1->SQR1 = (ADC_CHANNELS - 1) << 20; // amount of conversions
|
ADC1->SQR1 = (ADC_CHANNELS - 1) << 20; // amount of conversions
|
||||||
ADC1->CR1 = ADC_CR1_SCAN; // scan mode
|
ADC1->CR1 = ADC_CR1_SCAN; // scan mode
|
||||||
// DMA, continuous mode; enable vref & Tsens; enable SWSTART as trigger
|
// DMA, continuous mode; enable vref & Tsens; enable SWSTART as trigger
|
||||||
|
|||||||
@ -28,6 +28,8 @@ enum{
|
|||||||
ADC_CH_3,
|
ADC_CH_3,
|
||||||
ADC_CH_4,
|
ADC_CH_4,
|
||||||
ADC_CH_5,
|
ADC_CH_5,
|
||||||
|
ADC_POT0, // on-board pots (PC2 - in12, PC3 - in13)
|
||||||
|
ADC_POT1,
|
||||||
ADC_CH_TSEN, // T sensor
|
ADC_CH_TSEN, // T sensor
|
||||||
ADC_CH_VDD, // Vdd sensor
|
ADC_CH_VDD, // Vdd sensor
|
||||||
ADC_CHANNELS
|
ADC_CHANNELS
|
||||||
|
|||||||
@ -27,8 +27,11 @@
|
|||||||
#define FIXDL(m) do{m->length = 8;}while(0)
|
#define FIXDL(m) do{m->length = 8;}while(0)
|
||||||
|
|
||||||
/*********** START of all common functions list (for `funclist`) ***********/
|
/*********** START of all common functions list (for `funclist`) ***********/
|
||||||
|
static errcodes ping(CAN_message *m){
|
||||||
|
m->ID = the_conf.CANIDout; // change ID
|
||||||
|
return ERR_OK; // send same message
|
||||||
|
}
|
||||||
// reset MCU
|
// reset MCU
|
||||||
|
|
||||||
static errcodes reset(CAN_message _U_ *msg){
|
static errcodes reset(CAN_message _U_ *msg){
|
||||||
usart_send("Soft reset\n");
|
usart_send("Soft reset\n");
|
||||||
usart_transmit();
|
usart_transmit();
|
||||||
@ -127,6 +130,13 @@ static errcodes eswg(CAN_message *msg){
|
|||||||
FIXDL(msg);
|
FIXDL(msg);
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
// onboard LED
|
||||||
|
static errcodes led(CAN_message *m){
|
||||||
|
if(m->length > 4 && ISSETTER(m->data)) LED(m->data[4]);
|
||||||
|
m->data[4] = LED(-1);
|
||||||
|
FIXDL(m);
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
// common uint32_t setter/getter
|
// common uint32_t setter/getter
|
||||||
static errcodes u32setget(CAN_message *msg){
|
static errcodes u32setget(CAN_message *msg){
|
||||||
@ -176,6 +186,7 @@ typedef struct{
|
|||||||
// list of common (CAN/RS-232) functions
|
// list of common (CAN/RS-232) functions
|
||||||
// !!!!!!!!! Getters should set message length to 8 !!!!!!!!!!!
|
// !!!!!!!!! Getters should set message length to 8 !!!!!!!!!!!
|
||||||
static const commonfunction funclist[CMD_AMOUNT] = {
|
static const commonfunction funclist[CMD_AMOUNT] = {
|
||||||
|
[CMD_PING] = {ping, 0, 0, 0},
|
||||||
[CMD_RESET] = {reset, 0, 0, 0},
|
[CMD_RESET] = {reset, 0, 0, 0},
|
||||||
[CMD_TIME] = {time_getset, 0, 0, 0},
|
[CMD_TIME] = {time_getset, 0, 0, 0},
|
||||||
[CMD_MCUTEMP] = {mcut, 0, 0, 0},
|
[CMD_MCUTEMP] = {mcut, 0, 0, 0},
|
||||||
@ -191,6 +202,7 @@ static const commonfunction funclist[CMD_AMOUNT] = {
|
|||||||
[CMD_GETESWNOW] = {esw, 0, INT32_MAX, 0},
|
[CMD_GETESWNOW] = {esw, 0, INT32_MAX, 0},
|
||||||
[CMD_BOUNCE] = {u32setget, 0, 1000, 0},
|
[CMD_BOUNCE] = {u32setget, 0, 1000, 0},
|
||||||
[CMD_USARTSPEED] = {u32setget, 1200, 3000000, 0},
|
[CMD_USARTSPEED] = {u32setget, 1200, 3000000, 0},
|
||||||
|
[CMD_LED] = {led, 0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -35,8 +35,8 @@
|
|||||||
// error codes for answer message
|
// error codes for answer message
|
||||||
typedef enum{
|
typedef enum{
|
||||||
ERR_OK, // 0 - all OK
|
ERR_OK, // 0 - all OK
|
||||||
ERR_BADPAR, // 1 - parameter's value is wrong
|
ERR_BADPAR, // 1 - parameter is wrong
|
||||||
ERR_BADVAL, // 2 - wrong parameter's value
|
ERR_BADVAL, // 2 - wrong value
|
||||||
ERR_WRONGLEN, // 3 - wrong message length
|
ERR_WRONGLEN, // 3 - wrong message length
|
||||||
ERR_BADCMD, // 4 - unknown command
|
ERR_BADCMD, // 4 - unknown command
|
||||||
ERR_CANTRUN, // 5 - can't run given command due to bad parameters or other
|
ERR_CANTRUN, // 5 - can't run given command due to bad parameters or other
|
||||||
@ -45,6 +45,7 @@ typedef enum{
|
|||||||
|
|
||||||
// CAN commands indexes
|
// CAN commands indexes
|
||||||
enum{
|
enum{
|
||||||
|
CMD_PING, // just ping
|
||||||
CMD_RESET, // reset MCU
|
CMD_RESET, // reset MCU
|
||||||
CMD_TIME, // get/set Tms
|
CMD_TIME, // get/set Tms
|
||||||
CMD_MCUTEMP, // get MCU temperature (*10)
|
CMD_MCUTEMP, // get MCU temperature (*10)
|
||||||
@ -60,6 +61,7 @@ enum{
|
|||||||
CMD_GETESWNOW, // current ESW state, absolute
|
CMD_GETESWNOW, // current ESW state, absolute
|
||||||
CMD_BOUNCE, // get/set bounce constant (ms)
|
CMD_BOUNCE, // get/set bounce constant (ms)
|
||||||
CMD_USARTSPEED, // get/set USART1 speed (if encoder on RS-422)
|
CMD_USARTSPEED, // get/set USART1 speed (if encoder on RS-422)
|
||||||
|
CMD_LED, // onboard LED
|
||||||
// should be the last:
|
// should be the last:
|
||||||
CMD_AMOUNT // amount of CAN commands
|
CMD_AMOUNT // amount of CAN commands
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 13.0.1, 2024-06-03T20:25:16. -->
|
<!-- Written by QtCreator 13.0.1, 2024-06-04T14:30:38. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|||||||
@ -22,23 +22,28 @@
|
|||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
#include "strfunc.h"
|
#include "strfunc.h"
|
||||||
|
#include "uchar.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* pinout:
|
/* pinout:
|
||||||
|
|
||||||
|
Xn - inputs, Yn - outputs, ADCn - ADC inputs
|
||||||
|
|
||||||
| **Pin #** | **Pin name ** | **function** | **settings** | **comment ** |
|
| **Pin #** | **Pin name ** | **function** | **settings** | **comment ** |
|
||||||
| --------- | ------------- | ------------ | ---------------------- | --------------------------------------- |
|
| --------- | ------------- | ------------ | ---------------------- | --------------------------------------- |
|
||||||
| 15 | PC0/adcin10 | ADC4 | ADC in | |
|
| 15 | PC0/adcin10 | ADC4 | ADC in | current in (0..20mA) |
|
||||||
| 16 | PC1/adcin11 | ADC5 | ADC in | |
|
| 16 | PC1/adcin11 | ADC5 | ADC in | current in |
|
||||||
|
| 17 | PC2/adcin12 | ADC6 | ADC in | right potentiometer |
|
||||||
|
| 18 | PC3/adcin13 | ADC7 | ADC in | left pot |
|
||||||
| 23 | PA0 | Y3 | PPOUT | |
|
| 23 | PA0 | Y3 | PPOUT | |
|
||||||
| 24 | PA1/adcin1 | ADC0 | ADC in | |
|
| 24 | PA1/adcin1 | ADC0 | ADC in | voltage in (up to 11V) |
|
||||||
| 25 | PA2 | Y11 | PPOUT | |
|
| 25 | PA2 | Y11 | PPOUT | |
|
||||||
| 26 | PA3/adcin3 | ADC1 | ADC in | |
|
| 26 | PA3/adcin3 | ADC1 | ADC in | voltage in (up to 11V) |
|
||||||
| 31 | PA6 | Y10 | PPOUT | |
|
| 31 | PA6 | Y10 | PPOUT | |
|
||||||
| 32 | PA7 | Y7 | PPOUT | |
|
| 32 | PA7 | Y7 | PPOUT | |
|
||||||
| 33 | PC4/adcin14 | ADC2 | ADC in | |
|
| 33 | PC4/adcin14 | ADC2 | ADC in | voltage in |
|
||||||
| 34 | PC5/adcin15 | ADC3 | ADC in | |
|
| 34 | PC5/adcin15 | ADC3 | ADC in | current in |
|
||||||
| 37 | PB2/boot1 | PROG SW | PUIN | |
|
| 37 | PB2/boot1 | PROG SW | PUIN | onboard switch "Prog" (X8!!!) |
|
||||||
| 38 | PE7 | X14 | PUIN | |
|
| 38 | PE7 | X14 | PUIN | |
|
||||||
| 39 | PE8 | X15 | PUIN | |
|
| 39 | PE8 | X15 | PUIN | |
|
||||||
| 40 | PE9 | X12 | PUIN | |
|
| 40 | PE9 | X12 | PUIN | |
|
||||||
@ -54,13 +59,15 @@
|
|||||||
| 52 | PB13 | X0 | PUIN | |
|
| 52 | PB13 | X0 | PUIN | |
|
||||||
| 53 | PB14 | X1 | PUIN | |
|
| 53 | PB14 | X1 | PUIN | |
|
||||||
| 54 | PB15 | Y6 | PPOUT | |
|
| 54 | PB15 | Y6 | PPOUT | |
|
||||||
|
| 57 | PD10 | LED | PPOUT | onboard LED "RUN" |
|
||||||
| 59 | PD12 | Y5 | PPOUT | |
|
| 59 | PD12 | Y5 | PPOUT | |
|
||||||
|
| 64 | PC7 | | (FLIN) | (Not now) extern 24V power detect |
|
||||||
| 65 | PC8 | Y1 | PPOUT | |
|
| 65 | PC8 | Y1 | PPOUT | |
|
||||||
| 66 | PC9 | Y0 | PPOUT | |
|
| 66 | PC9 | Y0 | PPOUT | |
|
||||||
| 67 | PA8 | Y2 | PPOUT | |
|
| 67 | PA8 | Y2 | PPOUT | |
|
||||||
| 68 | PA9 | RS TX | AFPP | |
|
| 68 | PA9 | RS TX | AFPP | |
|
||||||
| 69 | PA10 | RS RX | FLIN | |
|
| 69 | PA10 | RS RX | FLIN | |
|
||||||
| 76 | PA14/SWCLK | 485 DE * | (default) | (Not now) |
|
| 76 | PA14/SWCLK | 485 DE * | (default) | (Not now) RS-485 Data Enable |
|
||||||
| 81 | PD0 | CAN RX | FLIN | |
|
| 81 | PD0 | CAN RX | FLIN | |
|
||||||
| 82 | PD1 | CAN TX | AFPP | |
|
| 82 | PD1 | CAN TX | AFPP | |
|
||||||
| 89 | PB3/JTDO | Y4 | PPOUT | |
|
| 89 | PB3/JTDO | Y4 | PPOUT | |
|
||||||
@ -77,14 +84,14 @@ void gpio_setup(void){
|
|||||||
AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
|
AFIO->MAPR = AFIO_MAPR_SWJ_CFG_JTAGDISABLE;
|
||||||
GPIOA->CRL = CRL(0, CNF_PPOUTPUT|MODE_NORMAL) | CRL(1, CNF_ANALOG) | CRL(2, CNF_PPOUTPUT|MODE_NORMAL) |
|
GPIOA->CRL = CRL(0, CNF_PPOUTPUT|MODE_NORMAL) | CRL(1, CNF_ANALOG) | CRL(2, CNF_PPOUTPUT|MODE_NORMAL) |
|
||||||
CRL(3, CNF_ANALOG) | CRL(6, CNF_PPOUTPUT|MODE_NORMAL) | CRL(7, CNF_PPOUTPUT|MODE_NORMAL);
|
CRL(3, CNF_ANALOG) | CRL(6, CNF_PPOUTPUT|MODE_NORMAL) | CRL(7, CNF_PPOUTPUT|MODE_NORMAL);
|
||||||
GPIOA->CRH = 0;
|
GPIOA->CRH = CRH(8, CNF_PPOUTPUT|MODE_NORMAL);
|
||||||
GPIOB->CRL = CRL(2, CNF_PUDINPUT);
|
GPIOB->CRL = CRL(2, CNF_PUDINPUT) | CRL(3, CNF_PPOUTPUT|MODE_NORMAL);
|
||||||
GPIOB->CRH = CRH(10, CNF_PUDINPUT) | CRH(11, CNF_PUDINPUT) | CRH(12, CNF_PUDINPUT) | CRH(13, CNF_PUDINPUT) |
|
GPIOB->CRH = CRH(10, CNF_PUDINPUT) | CRH(11, CNF_PUDINPUT) | CRH(12, CNF_PUDINPUT) | CRH(13, CNF_PUDINPUT) |
|
||||||
CRH(14, CNF_PUDINPUT) | CRH(15, CNF_PPOUTPUT|MODE_NORMAL);
|
CRH(14, CNF_PUDINPUT) | CRH(15, CNF_PPOUTPUT|MODE_NORMAL);
|
||||||
GPIOC-> CRL = CRL(0, CNF_ANALOG) | CRL(1, CNF_ANALOG) | CRL(4, CNF_ANALOG) | CRL(5, CNF_ANALOG);
|
GPIOC-> CRL = CRL(0, CNF_ANALOG) | CRL(1, CNF_ANALOG) | CRL(4, CNF_ANALOG) | CRL(5, CNF_ANALOG);
|
||||||
GPIOC->CRH = CRH(8, CNF_PPOUTPUT|MODE_NORMAL) | CRH(9, CNF_PPOUTPUT|MODE_NORMAL);
|
GPIOC->CRH = CRH(8, CNF_PPOUTPUT|MODE_NORMAL) | CRH(9, CNF_PPOUTPUT|MODE_NORMAL);
|
||||||
GPIOD->CRL = 0;
|
GPIOD->CRL = 0;
|
||||||
GPIOD->CRH = CRH(12, CNF_PPOUTPUT|MODE_NORMAL);
|
GPIOD->CRH = CRH(10, CNF_PPOUTPUT|MODE_NORMAL) | CRH(12, CNF_PPOUTPUT|MODE_NORMAL);
|
||||||
GPIOE->CRL = CRL(7, CNF_PUDINPUT);
|
GPIOE->CRL = CRL(7, CNF_PUDINPUT);
|
||||||
GPIOE->CRH = CRH(8, CNF_PUDINPUT) | CRH(9, CNF_PUDINPUT) | CRH(10, CNF_PUDINPUT) | CRH(11, CNF_PUDINPUT) |
|
GPIOE->CRH = CRH(8, CNF_PUDINPUT) | CRH(9, CNF_PUDINPUT) | CRH(10, CNF_PUDINPUT) | CRH(11, CNF_PUDINPUT) |
|
||||||
CRH(12, CNF_PUDINPUT) | CRH(13, CNF_PUDINPUT) | CRH(14, CNF_PUDINPUT) | CRH(15, CNF_PUDINPUT);
|
CRH(12, CNF_PUDINPUT) | CRH(13, CNF_PUDINPUT) | CRH(14, CNF_PUDINPUT) | CRH(15, CNF_PUDINPUT);
|
||||||
@ -92,7 +99,7 @@ void gpio_setup(void){
|
|||||||
GPIOA->ODR = 0;
|
GPIOA->ODR = 0;
|
||||||
GPIOB->ODR = (1<<2) | (1<<10) | (1<<11) | (1<<12) | (1<<13) | (1<<14);
|
GPIOB->ODR = (1<<2) | (1<<10) | (1<<11) | (1<<12) | (1<<13) | (1<<14);
|
||||||
GPIOC->ODR = 0;
|
GPIOC->ODR = 0;
|
||||||
GPIOD->ODR = 0;
|
GPIOD->ODR = (1<<10); // turn off LED
|
||||||
GPIOE->ODR = (1<<7) | (1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<12) | (1<<13) | (1<<14) | (1<<15);
|
GPIOE->ODR = (1<<7) | (1<<8) | (1<<9) | (1<<10) | (1<<11) | (1<<12) | (1<<13) | (1<<14) | (1<<15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,9 +132,9 @@ static const pin_t IN[INMAX+1] = { // youbannye uskoglazye pidarasy! Ready to fu
|
|||||||
{GPIOB, 1<<10}, // X5 - PB10
|
{GPIOB, 1<<10}, // X5 - PB10
|
||||||
{GPIOE, 1<<13}, // X6 - PE13
|
{GPIOE, 1<<13}, // X6 - PE13
|
||||||
{GPIOE, 1<<14}, // X7 - PE14
|
{GPIOE, 1<<14}, // X7 - PE14
|
||||||
{NULL, 0}, // X8 - absent
|
{GPIOB, 1<<2}, // X8 - onboard switch
|
||||||
{NULL, 0}, // X9 - absent
|
{NULL, 0}, // X9 - absent
|
||||||
{GPIOE, 1<11}, // X10 - PE11
|
{GPIOE, 1<<11}, // X10 - PE11
|
||||||
{GPIOE, 1<<12}, // X11 - PE12
|
{GPIOE, 1<<12}, // X11 - PE12
|
||||||
{GPIOE, 1<<9}, // X12 - PE9
|
{GPIOE, 1<<9}, // X12 - PE9
|
||||||
{GPIOE, 1<<10}, // X13 - PE10
|
{GPIOE, 1<<10}, // X13 - PE10
|
||||||
@ -160,6 +167,15 @@ uint32_t outchannels(){
|
|||||||
return 0b110011111111;
|
return 0b110011111111;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// turn on/off onboard LED; if onoff < 0 - return current state
|
||||||
|
uint8_t LED(int onoff){
|
||||||
|
if(onoff > -1){
|
||||||
|
if(onoff) pin_clear(LEDPORT, LEDPIN);
|
||||||
|
else pin_set(LEDPORT, LEDPIN);
|
||||||
|
}
|
||||||
|
return ((LEDPORT->IDR & LEDPIN) ? 0 : 1); // inverse!
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set_relay - turn on/off relay `Nch` (if Nch > OUTMAX - all)
|
* @brief set_relay - turn on/off relay `Nch` (if Nch > OUTMAX - all)
|
||||||
* @param Nch - single relay channel No or >Ymax to set/reset all relays
|
* @param Nch - single relay channel No or >Ymax to set/reset all relays
|
||||||
@ -195,9 +211,12 @@ static int readpins(uint8_t Nch, const pin_t *pins, uint8_t max){
|
|||||||
for(int i = max; i > -1; --i){
|
for(int i = max; i > -1; --i){
|
||||||
val <<= 1;
|
val <<= 1;
|
||||||
int p = gpin(i);
|
int p = gpin(i);
|
||||||
if(p > -1) val |= gpin(i);
|
if(p == 1){
|
||||||
|
//usart_send("pin"); usart_send(u2str(i)); usart_send("=1\n");
|
||||||
|
val |= p;
|
||||||
}
|
}
|
||||||
usart_send("readpins, val="); usart_send(i2str(val)); newline();
|
}
|
||||||
|
//usart_send("readpins, val="); usart_send(i2str(val)); newline();
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
return gpin(Nch);
|
return gpin(Nch);
|
||||||
@ -227,7 +246,7 @@ static uint32_t lastET[INMAX+1] = {0}; // last changing time
|
|||||||
// anti-bouce process esw
|
// anti-bouce process esw
|
||||||
void proc_esw(){
|
void proc_esw(){
|
||||||
uint32_t mask = 1, oldesw = ESW_ab_values;
|
uint32_t mask = 1, oldesw = ESW_ab_values;
|
||||||
for(uint8_t i = 0; i <= OUTMAX; ++i, mask <<= 1){
|
for(uint8_t i = 0; i <= INMAX; ++i, mask <<= 1){
|
||||||
if(Tms - lastET[i] < the_conf.bouncetime) continue;
|
if(Tms - lastET[i] < the_conf.bouncetime) continue;
|
||||||
if(NULL == IN[i].port) continue;
|
if(NULL == IN[i].port) continue;
|
||||||
uint32_t now = pin_read(IN[i].port, IN[i].pin);
|
uint32_t now = pin_read(IN[i].port, IN[i].pin);
|
||||||
@ -236,7 +255,7 @@ void proc_esw(){
|
|||||||
lastET[i] = Tms;
|
lastET[i] = Tms;
|
||||||
}
|
}
|
||||||
if(oldesw != ESW_ab_values){
|
if(oldesw != ESW_ab_values){
|
||||||
usart_send("esw="); usart_send(u2str(ESW_ab_values)); newline();
|
//usart_send("esw="); usart_send(u2str(ESW_ab_values)); newline();
|
||||||
CAN_message msg = {.ID = the_conf.CANIDout, .length = 8};
|
CAN_message msg = {.ID = the_conf.CANIDout, .length = 8};
|
||||||
msg.data[0] = CMD_GETESW;
|
msg.data[0] = CMD_GETESW;
|
||||||
*((uint32_t*)(&msg.data[4])) = ESW_ab_values;
|
*((uint32_t*)(&msg.data[4])) = ESW_ab_values;
|
||||||
|
|||||||
@ -34,6 +34,10 @@
|
|||||||
#define INMAX (15)
|
#define INMAX (15)
|
||||||
#define OUTMAX (11)
|
#define OUTMAX (11)
|
||||||
|
|
||||||
|
// onboard LED - PD10
|
||||||
|
#define LEDPORT GPIOD
|
||||||
|
#define LEDPIN (1<<10)
|
||||||
|
|
||||||
extern volatile uint32_t Tms;
|
extern volatile uint32_t Tms;
|
||||||
|
|
||||||
void gpio_setup(void);
|
void gpio_setup(void);
|
||||||
@ -44,6 +48,7 @@ int get_esw(uint8_t Nch);
|
|||||||
void proc_esw();
|
void proc_esw();
|
||||||
uint32_t get_ab_esw();
|
uint32_t get_ab_esw();
|
||||||
|
|
||||||
|
uint8_t LED(int onoff);
|
||||||
uint32_t inchannels();
|
uint32_t inchannels();
|
||||||
uint32_t outchannels();
|
uint32_t outchannels();
|
||||||
int set_relay(uint8_t Nch, uint32_t val);
|
int set_relay(uint8_t Nch, uint32_t val);
|
||||||
|
|||||||
@ -67,8 +67,10 @@ static const funcdescr funclist[] = {
|
|||||||
{"saveconf", CMD_SAVECONF, "save configuration"},
|
{"saveconf", CMD_SAVECONF, "save configuration"},
|
||||||
{"usartspeed", CMD_USARTSPEED, "get/set USART1 speed"},
|
{"usartspeed", CMD_USARTSPEED, "get/set USART1 speed"},
|
||||||
{NULL, 0, "IN/OUT"},
|
{NULL, 0, "IN/OUT"},
|
||||||
|
{"adc", CMD_ADCRAW, "get raw ADC values for given channel"},
|
||||||
{"esw", CMD_GETESW, "anti-bounce read inputs"},
|
{"esw", CMD_GETESW, "anti-bounce read inputs"},
|
||||||
{"eswnow", CMD_GETESWNOW, "read current inputs' state"},
|
{"eswnow", CMD_GETESWNOW, "read current inputs' state"},
|
||||||
|
{"led", CMD_LED, "work with onboard LED"},
|
||||||
{"relay", CMD_RELAY, "get/set relay state (0 - off, 1 - on)"},
|
{"relay", CMD_RELAY, "get/set relay state (0 - off, 1 - on)"},
|
||||||
{NULL, 0, "Other commands"},
|
{NULL, 0, "Other commands"},
|
||||||
{"mcutemp", CMD_MCUTEMP, "get MCU temperature (*10degrC)"},
|
{"mcutemp", CMD_MCUTEMP, "get MCU temperature (*10degrC)"},
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
#define BUILD_NUMBER "50"
|
#define BUILD_NUMBER "56"
|
||||||
#define BUILD_DATE "2024-06-03"
|
#define BUILD_DATE "2024-06-04"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user