diff --git a/F0-nolib/CANbus_stepper/src/canstepper.bin b/F0-nolib/CANbus_stepper/src/canstepper.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/Chiller/chiller.bin b/F0-nolib/Chiller/chiller.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/F0_testbrd/pl2303.bin b/F0-nolib/F0_testbrd/pl2303.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/QuadEncoder/encoder.bin b/F0-nolib/QuadEncoder/encoder.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/Servo/servo.bin b/F0-nolib/Servo/servo.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/Socket_fans/sockfans.bin b/F0-nolib/Socket_fans/sockfans.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/TM1637/tm1637.bin b/F0-nolib/TM1637/tm1637.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/USBHID/usbhid.bin b/F0-nolib/USBHID/usbhid.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/USB_pl2303_snippet/usb.bin b/F0-nolib/USB_pl2303_snippet/usb.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/blink/blink.bin b/F0-nolib/blink/blink.bin old mode 100644 new mode 100755 diff --git a/F0-nolib/canbus/src/canbus.bin b/F0-nolib/canbus/src/canbus.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/htu21d_nucleo/usart.bin b/F0-nolib/htu21d_nucleo/usart.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/inc/F0 b/F0-nolib/inc/F0 index ba957c0..0be4819 120000 --- a/F0-nolib/inc/F0 +++ b/F0-nolib/inc/F0 @@ -1 +1 @@ -/home/eddy/Yandex.Disk/Projects/stm32samples/F0-nolib/inc/Fx \ No newline at end of file +Fx \ No newline at end of file diff --git a/F0-nolib/inc/cm/core_cmFunc.h b/F0-nolib/inc/cm/core_cmFunc.h index a1bd88c..bdc54e6 100644 --- a/F0-nolib/inc/cm/core_cmFunc.h +++ b/F0-nolib/inc/cm/core_cmFunc.h @@ -453,7 +453,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void) */ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) { - __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp"); + __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack)); } diff --git a/F0-nolib/morze/morze.bin b/F0-nolib/morze/morze.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/pl2303/pl2303.bin b/F0-nolib/pl2303/pl2303.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/tsys01_nucleo/tsys01.bin b/F0-nolib/tsys01_nucleo/tsys01.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/uart_blink/uartblink.bin b/F0-nolib/uart_blink/uartblink.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/uart_blink_dma/uartblink.bin b/F0-nolib/uart_blink_dma/uartblink.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/uart_nucleo/usart.bin b/F0-nolib/uart_nucleo/usart.bin old mode 100755 new mode 100644 diff --git a/F0-nolib/usbcan/can.c b/F0-nolib/usbcan/can.c index 3e1868d..173f917 100644 --- a/F0-nolib/usbcan/can.c +++ b/F0-nolib/usbcan/can.c @@ -48,14 +48,25 @@ CAN_status CAN_get_status(){ #ifdef EBUG if(st == CAN_FIFO_OVERRUN) MSG("fifo 0 overrun\n"); #endif - if(st == CAN_FIFO_OVERRUN) can_status = CAN_READY; + if(st == CAN_FIFO_OVERRUN){ + SEND("FIFO overrun\n"); + can_status = CAN_READY; + } return st; } // push next message into buffer; return 1 if buffer overfull static int CAN_messagebuf_push(CAN_message *msg){ //MSG("Try to push\n"); - if(first_free_idx == first_nonfree_idx) return 1; // no free space +#ifdef EBUG + SEND("push\n"); +#endif + if(first_free_idx == first_nonfree_idx){ +#ifdef EBUG + SEND("INBUF OVERFULL\n"); +#endif + return 1; // no free space + } if(first_nonfree_idx < 0) first_nonfree_idx = 0; // first message in empty buffer memcpy(&messages[first_free_idx++], msg, sizeof(CAN_message)); // need to roll? @@ -155,7 +166,7 @@ void CAN_setup(uint16_t speed){ CAN->sFilterRegister[0].FR1 = (1<<21)|(1<<5); // all odd IDs CAN->FFA1R = 2; // filter 1 for FIFO1, filter 0 - for FIFO0 CAN->sFilterRegister[1].FR1 = (1<<21); // all even IDs - CAN->FMR &=~ CAN_FMR_FINIT; /* (12) */ + CAN->FMR &= ~CAN_FMR_FINIT; /* (12) */ CAN->IER |= CAN_IER_ERRIE | CAN_IER_FOVIE0 | CAN_IER_FOVIE1; /* (13) */ /* Configure IT */ @@ -202,8 +213,8 @@ void can_proc(){ case 7: errmsg = "(set by software)"; break; } SEND(errmsg); SEND(" error\n"); - if(CAN->ESR & CAN_ESR_BOFF) SEND("Bus off"); - if(CAN->ESR & CAN_ESR_EPVF) SEND("Passive error limit"); + if(CAN->ESR & CAN_ESR_BOFF) SEND("Bus off "); + if(CAN->ESR & CAN_ESR_EPVF) SEND("Passive error limit "); if(CAN->ESR & CAN_ESR_EWGF) SEND("Error counter limit"); NL(); // request abort for all mailboxes @@ -287,6 +298,9 @@ static void can_process_fifo(uint8_t fifo_num){ LED_on(LED1); // Turn on LED1 - message received CAN_FIFOMailBox_TypeDef *box = &CAN->sFIFOMailBox[fifo_num]; volatile uint32_t *RFxR = (fifo_num) ? &CAN->RF1R : &CAN->RF0R; +#ifdef EBUG + printu(*RFxR & CAN_RF0R_FMP0); SEND(" messages in FIFO\n"); +#endif // read all while(*RFxR & CAN_RF0R_FMP0){ // amount of messages pending // CAN_RDTxR: (16-31) - timestamp, (8-15) - filter match index, (0-3) - data length @@ -334,6 +348,13 @@ static void can_process_fifo(uint8_t fifo_num){ } void cec_can_isr(){ + /* + if(CAN->RF0R & CAN_RF0R_FOVR0){ + can_process_fifo(0); + } + if(CAN->RF1R & CAN_RF1R_FOVR1){ + can_process_fifo(1); + }*/ if(CAN->RF0R & CAN_RF0R_FOVR0){ // FIFO overrun CAN->RF0R &= ~CAN_RF0R_FOVR0; can_status = CAN_FIFO_OVERRUN; diff --git a/F0-nolib/usbcan/main.c b/F0-nolib/usbcan/main.c index 8a6decc..e1bea7e 100644 --- a/F0-nolib/usbcan/main.c +++ b/F0-nolib/usbcan/main.c @@ -76,7 +76,9 @@ int main(void){ USB_setup(); CAN_setup(100); RCC->CSR |= RCC_CSR_RMVF; // remove reset flags +#ifndef EBUG iwdg_setup(); +#endif while (1){ IWDG->KR = IWDG_REFRESH; // refresh watchdog @@ -90,22 +92,23 @@ int main(void){ SEND("CAN bus fifo overrun occured!\n"); sendbuf(); } - can_mesg = CAN_messagebuf_pop(); - if(can_mesg && isgood(can_mesg->ID)){ - LED_on(LED0); - lastT = Tms; - if(!lastT) lastT = 1; - if(ShowMsgs){ // new data in buff - IWDG->KR = IWDG_REFRESH; - len = can_mesg->length; - printu(Tms); - SEND(" #"); - printuhex(can_mesg->ID); - for(ctr = 0; ctr < len; ++ctr){ - SEND(" "); - printuhex(can_mesg->data[ctr]); + while((can_mesg = CAN_messagebuf_pop())){ + if(can_mesg && isgood(can_mesg->ID)){ + LED_on(LED0); + lastT = Tms; + if(!lastT) lastT = 1; + if(ShowMsgs){ // new data in buff + IWDG->KR = IWDG_REFRESH; + len = can_mesg->length; + printu(Tms); + SEND(" #"); + printuhex(can_mesg->ID); + for(ctr = 0; ctr < len; ++ctr){ + SEND(" "); + printuhex(can_mesg->data[ctr]); + } + newline(); sendbuf(); } - newline(); sendbuf(); } } if((txt = get_USB())){ diff --git a/F0-nolib/usbcan/usbcan.bin b/F0-nolib/usbcan/usbcan.bin index cb484e6..707e7c5 100755 Binary files a/F0-nolib/usbcan/usbcan.bin and b/F0-nolib/usbcan/usbcan.bin differ diff --git a/F0-nolib/usbcan_relay/Readme.md b/F0-nolib/usbcan_relay/Readme.md index 5cfc4f6..e2302c4 100644 --- a/F0-nolib/usbcan_relay/Readme.md +++ b/F0-nolib/usbcan_relay/Readme.md @@ -19,3 +19,13 @@ Pinout: - PB12..15 - LED0..3 outputs (direct outputs without any protection!!!) The pins LEDr0 and LEDr1 are indicated relay works (12V through 2.2kOhm resistor) + + +### Buttons standalone + +BTN1 - switch relay1 + +BTN2 - switch relay 2 + +BTN3 - change PWM0: hold to turn ON or turn OFF; press shortly BTN1/BTN2 to increase/decrease PWM0 to 1, +hold BTN1/BTN2 to inc/dec PWM0 to 25 (do as many presses as need). \ No newline at end of file diff --git a/F0-nolib/usbcan_relay/buttons.c b/F0-nolib/usbcan_relay/buttons.c index 24a032f..c61ff57 100644 --- a/F0-nolib/usbcan_relay/buttons.c +++ b/F0-nolib/usbcan_relay/buttons.c @@ -27,6 +27,8 @@ typedef struct{ static keybase allkeys[BTNSNO] = {0}; // array for buttons' states +uint32_t lastUnsleep = 0; // last keys activity time + void process_keys(){ static uint32_t lastT = 0; if(Tms == lastT) return; @@ -61,6 +63,7 @@ void process_keys(){ } if(e != k->event){ k->lastTms = Tms; + lastUnsleep = Tms; } } } @@ -79,3 +82,9 @@ keyevent keystate(uint8_t k, uint32_t *T){ if(T) *T = allkeys[k].lastTms; return evt; } + +// getter of keyevent for allkeys[] +keyevent keyevt(uint8_t k){ + if(k >= BTNSNO) return EVT_NONE; + return allkeys[k].event; +} diff --git a/F0-nolib/usbcan_relay/buttons.h b/F0-nolib/usbcan_relay/buttons.h index 7906e72..79c5c47 100644 --- a/F0-nolib/usbcan_relay/buttons.h +++ b/F0-nolib/usbcan_relay/buttons.h @@ -37,6 +37,7 @@ extern uint32_t lastUnsleep; // last keys activity time void process_keys(); keyevent keystate(uint8_t k, uint32_t *T); +keyevent keyevt(uint8_t k); #define BUTTONS_H__ #endif // BUTTONS_H__ diff --git a/F0-nolib/usbcan_relay/can.c b/F0-nolib/usbcan_relay/can.c index a51641c..24bc8d5 100644 --- a/F0-nolib/usbcan_relay/can.c +++ b/F0-nolib/usbcan_relay/can.c @@ -27,7 +27,7 @@ static CAN_message messages[CAN_INMESSAGE_SIZE]; static uint8_t first_free_idx = 0; // index of first empty cell static int8_t first_nonfree_idx = -1; // index of first data cell -static uint16_t oldspeed = 100; // speed of last init +static uint16_t oldspeed = DEFAULT_CAN_SPEED; // speed of last init #ifdef EBUG static uint32_t last_err_code = 0; @@ -42,10 +42,6 @@ static CAN_message *flood_msg = NULL; // == loc_flood_msg - to flood CAN_status CAN_get_status(){ CAN_status st = can_status; - // give overrun message only once -#ifdef EBUG - if(st == CAN_FIFO_OVERRUN) MSG("fifo 0 overrun\n"); -#endif if(st == CAN_FIFO_OVERRUN) can_status = CAN_READY; return st; } @@ -214,9 +210,7 @@ CAN_status can_send(uint8_t *msg, uint8_t len, uint16_t target_id){ if(CAN->TSR & (CAN_TSR_TME)){ mailbox = (CAN->TSR & CAN_TSR_CODE) >> 24; }else{ // no free mailboxes -#ifdef EBUG - MSG("No free mailboxes"); NL(); -#endif + //SEND("No free mailboxes"); NL(); return CAN_BUSY; } #ifdef EBUG @@ -313,7 +307,7 @@ static void can_process_fifo(uint8_t fifo_num){ } } if(msg.ID == CANID) parseCANcommand(&msg); - else if(CAN_messagebuf_push(&msg)) return; // error: buffer is full, try later + if(CAN_messagebuf_push(&msg)) return; // error: buffer is full, try later *RFxR |= CAN_RF0R_RFOM0; // release fifo for access to next message } //if(*RFxR & CAN_RF0R_FULL0) *RFxR &= ~CAN_RF0R_FULL0; diff --git a/F0-nolib/usbcan_relay/canproto.c b/F0-nolib/usbcan_relay/canproto.c index cc0d1c5..46ab9c2 100644 --- a/F0-nolib/usbcan_relay/canproto.c +++ b/F0-nolib/usbcan_relay/canproto.c @@ -36,7 +36,7 @@ * CAN_CMD_LED: data[1] = LEDs state (bits 0..3 for LEDs number 0..3) * CAN_CMD_MCU: data[2,3] = int16_t MCUT*10, data[4,5] = uint16_t Vdd*100 (LITTLE endian!) * CAN_CMD_PWM: data[1..3] = pwm value for each channel (0..2) - * CAN_CMD_RELAY: data[0] = (bits 0 & 1) - state of relay N] + * CAN_CMD_RELAY: data[1] = (bits 0 & 1) - state of relay N] * CAN_CMD_TMS: data[4..7] = Tms (LITTLE endian!) */ @@ -56,13 +56,19 @@ TRUE_INLINE uint8_t ADCget(uint8_t values[8]){ TRUE_INLINE void BTNSget(uint8_t values[8]){ uint32_t T; - for(uint8_t i = 0; i < BTNSNO; ++i){ + uint8_t start = 0, stop = BTNSNO; + if(values[1] < BTNSNO){ // check only one button + start = values[1]; stop = start + 1; + } + for(uint8_t i = start; i < stop; ++i){ values[1] = i; values[2] = keystate(i, &T); values[3] = 0; *((uint32_t*)&values[4]) = T; - int N = 1000; - while(CAN_BUSY == can_send(values, 8, OUTPID)) if(--N == 0) break; + T = Tms; + while(CAN_BUSY == can_send(values, 8, OUTPID)){ + if(Tms - T > 5) break; + } } } @@ -141,22 +147,24 @@ void parseCANcommand(CAN_message *msg){ len = ADCget(outpdata); break; case CAN_CMD_BTNS: + if(msg->length == 2) outpdata[1] = msg->data[1]; // check only one button + else outpdata[1] = BTNSNO; BTNSget(outpdata); return; break; case CAN_CMD_LED: - if(setter) LEDSset(msg->data); + if(setter && msg->length > 1) LEDSset(msg->data); len = LEDSget(outpdata); break; case CAN_CMD_MCU: len = MCUget(outpdata); break; case CAN_CMD_PWM: - if(setter) PWMset(msg->data); + if(setter && msg->length > 3) PWMset(msg->data); len = PWMget(outpdata); break; case CAN_CMD_RELAY: - if(setter) Rset(msg->data); + if(setter && msg->length > 1) Rset(msg->data); len = Rget(outpdata); break; case CAN_CMD_TMS: diff --git a/F0-nolib/usbcan_relay/canproto.h b/F0-nolib/usbcan_relay/canproto.h index 2de8898..433f100 100644 --- a/F0-nolib/usbcan_relay/canproto.h +++ b/F0-nolib/usbcan_relay/canproto.h @@ -40,7 +40,7 @@ typedef enum{ } CAN_commands; // output messages identifier -#define OUTPID (CANID + 0x100) +#define OUTPID (CANID) void parseCANcommand(CAN_message *msg); diff --git a/F0-nolib/usbcan_relay/custom_buttons.c b/F0-nolib/usbcan_relay/custom_buttons.c new file mode 100644 index 0000000..8a4b241 --- /dev/null +++ b/F0-nolib/usbcan_relay/custom_buttons.c @@ -0,0 +1,67 @@ +/* + * This file is part of the canrelay project. + * Copyright 2021 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// custom standalone buttons reaction + +#include +#include "buttons.h" +#include "custom_buttons.h" +#include "hardware.h" + + +/* + * check buttons, on long press of button: + * 1 - switch relay1 + * 2 - switch relay2 + * 3 - work with PWM out 0 (when btn3 pressed, btn1 increased & btn2 decreased PWM width) + * press once btn2/3 to change PWM @1, hold to change @25 (repeat as many times as need) + */ +void custom_buttons_process(){ + static uint32_t lastT = 0; + static uint8_t pwmval = 127; + static uint8_t trig = 0; // == 1 if given btn3 was off + if(lastUnsleep == lastT) return; // no buttons activity + lastT = lastUnsleep; + if(keyevt(3) == EVT_HOLD){ // PWM + if(keyevt(2) == EVT_HOLD){ // decrease PWM by 25 + if(pwmval > 25) pwmval -= 25; + else pwmval = 0; + }else if(keyevt(2) == EVT_PRESS){ // decrease PWM by 1 + if(pwmval > 0) --pwmval; + }else if(keyevt(1) == EVT_HOLD){ // increase PWM by 25 + if(pwmval < 230) pwmval += 25; + else pwmval = 255; + }else if(keyevt(1) == EVT_PRESS){ + if(pwmval < 254) ++pwmval; + } + if(trig == 0){ // first hold after release + if(TIM1->CCR1) TIM1->CCR1 = 0; // turn off if was ON + else{ + TIM1->CCR1 = pwmval; + trig = 1; + } + }else TIM1->CCR1 = pwmval; + return; + }else trig = 0; + if(keyevt(1) == EVT_HOLD){ // relay1 + Relay_TGL(0); + } + if(keyevt(2) == EVT_HOLD){ // relay2 + Relay_TGL(1); + } +} diff --git a/F0-nolib/usbcan_relay/custom_buttons.h b/F0-nolib/usbcan_relay/custom_buttons.h new file mode 100644 index 0000000..426f10f --- /dev/null +++ b/F0-nolib/usbcan_relay/custom_buttons.h @@ -0,0 +1,25 @@ +/* + * This file is part of the canrelay project. + * Copyright 2021 Edward V. Emelianov . + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#ifndef CUSTOM_BUTTONS_H__ +#define CUSTOM_BUTTONS_H__ + +void custom_buttons_process(); + +#endif // CUSTOM_BUTTONS_H__ diff --git a/F0-nolib/usbcan_relay/hardware.h b/F0-nolib/usbcan_relay/hardware.h index 00f5dd3..0fce465 100644 --- a/F0-nolib/usbcan_relay/hardware.h +++ b/F0-nolib/usbcan_relay/hardware.h @@ -22,6 +22,9 @@ #include +// default CAN bus speed in kbaud +#define DEFAULT_CAN_SPEED (250) + #define SYSMEM03x 0x1FFFEC00 #define SYSMEM04x 0x1FFFC400 #define SYSMEM05x 0x1FFFEC00 @@ -55,6 +58,7 @@ extern GPIO_TypeDef *R_ports[RelaysNO]; extern const uint32_t R_pins[RelaysNO]; #define Relay_ON(x) do{pin_set(R_ports[x], R_pins[x]);}while(0) #define Relay_OFF(x) do{pin_clear(R_ports[x], R_pins[x]);}while(0) +#define Relay_TGL(x) do{pin_toggle(R_ports[x], R_pins[x]);}while(0) #define Relay_chk(x) (pin_read(R_ports[x], R_pins[x])) // Buttons amount diff --git a/F0-nolib/usbcan_relay/main.c b/F0-nolib/usbcan_relay/main.c index 4d6343e..4fbb590 100644 --- a/F0-nolib/usbcan_relay/main.c +++ b/F0-nolib/usbcan_relay/main.c @@ -19,6 +19,7 @@ #include "adc.h" #include "buttons.h" #include "can.h" +#include "custom_buttons.h" #include "hardware.h" #include "proto.h" #include "usb.h" @@ -74,32 +75,34 @@ int main(void){ adc_setup(); tim1_setup(); USB_setup(); - CAN_setup(100); + CAN_setup(DEFAULT_CAN_SPEED); RCC->CSR |= RCC_CSR_RMVF; // remove reset flags iwdg_setup(); while (1){ IWDG->KR = IWDG_REFRESH; // refresh watchdog process_keys(); + custom_buttons_process(); can_proc(); usb_proc(); if(CAN_get_status() == CAN_FIFO_OVERRUN){ SEND("CAN bus fifo overrun occured!\n"); sendbuf(); } - can_mesg = CAN_messagebuf_pop(); - if(can_mesg && isgood(can_mesg->ID)){ - if(ShowMsgs){ // new data in buff - IWDG->KR = IWDG_REFRESH; - len = can_mesg->length; - printu(Tms); - SEND(" #"); - printuhex(can_mesg->ID); - for(ctr = 0; ctr < len; ++ctr){ - SEND(" "); - printuhex(can_mesg->data[ctr]); + while((can_mesg = CAN_messagebuf_pop())){ + if(can_mesg && isgood(can_mesg->ID)){ + if(ShowMsgs){ // new data in buff + IWDG->KR = IWDG_REFRESH; + len = can_mesg->length; + printu(Tms); + SEND(" #"); + printuhex(can_mesg->ID); + for(ctr = 0; ctr < len; ++ctr){ + SEND(" "); + printuhex(can_mesg->data[ctr]); + } + newline(); sendbuf(); } - newline(); sendbuf(); } } if((txt = get_USB())){ diff --git a/F0-nolib/usbcan_relay/usbcan.bin b/F0-nolib/usbcan_relay/usbcan.bin index 84068e3..299e9c7 100755 Binary files a/F0-nolib/usbcan_relay/usbcan.bin and b/F0-nolib/usbcan_relay/usbcan.bin differ diff --git a/F0/blink/blink.bin b/F0/blink/blink.bin old mode 100755 new mode 100644 diff --git a/F0/uart/uart.bin b/F0/uart/uart.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/BMP180/BMP180.bin b/F1-nolib/BMP180/BMP180.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/BMP280/BMP280.bin b/F1-nolib/BMP280/BMP280.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/CDC_ACM/cdcacm.bin b/F1-nolib/CDC_ACM/cdcacm.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/DHT22_DHT11/DHT22.bin b/F1-nolib/DHT22_DHT11/DHT22.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/DS18/DS18.bin b/F1-nolib/DS18/DS18.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/F1_testbrd/pl2303.bin b/F1-nolib/F1_testbrd/pl2303.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/I2Cscan/I2Cscan.bin b/F1-nolib/I2Cscan/I2Cscan.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/LED_Screen/LEDscreen.bin b/F1-nolib/LED_Screen/LEDscreen.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/LED_Screen/genlist b/F1-nolib/LED_Screen/genlist old mode 100755 new mode 100644 diff --git a/F1-nolib/LED_Screen/scrtest/scrtest b/F1-nolib/LED_Screen/scrtest/scrtest old mode 100755 new mode 100644 diff --git a/F1-nolib/MAX7219_screen/MAX7219.bin b/F1-nolib/MAX7219_screen/MAX7219.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/PL2303/pl2303.bin b/F1-nolib/PL2303/pl2303.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/RGB_LED_Screen/RGBLEDscreen.bin b/F1-nolib/RGB_LED_Screen/RGBLEDscreen.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/RGB_LED_Screen/getrand b/F1-nolib/RGB_LED_Screen/getrand old mode 100755 new mode 100644 diff --git a/F1-nolib/RGB_LED_Screen/proto.c b/F1-nolib/RGB_LED_Screen/proto.c deleted file mode 100644 index 63ffb0f..0000000 --- a/F1-nolib/RGB_LED_Screen/proto.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * This file is part of the RGBLEDscreen project. - * Copyright 2020 Edward V. Emelianov . - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "adcrandom.h" -#include "balls.h" -#include "fonts.h" -#include "proto.h" -#include "screen.h" -#include "usb.h" - -extern uint8_t countms, rainbow, balls; -extern uint32_t Tms; - -char *omit_spaces(const char *buf){ - while(*buf){ - if(*buf > ' ') break; - ++buf; - } - return (char*)buf; -} - -// In case of overflow return `buf` and N==0xffffffff -// read decimal number & return pointer to next non-number symbol -static char *getdec(const char *buf, uint32_t *N){ - char *start = (char*)buf; - uint32_t num = 0; - while(*buf){ - char c = *buf; - if(c < '0' || c > '9'){ - break; - } - if(num > 429496729 || (num == 429496729 && c > '5')){ // overflow - *N = 0xffffff; - return start; - } - num *= 10; - num += c - '0'; - ++buf; - } - *N = num; - return (char*)buf; -} -// read hexadecimal number (without 0x prefix!) -static char *gethex(const char *buf, uint32_t *N){ - char *start = (char*)buf; - uint32_t num = 0; - while(*buf){ - char c = *buf; - uint8_t M = 0; - if(c >= '0' && c <= '9'){ - M = '0'; - }else if(c >= 'A' && c <= 'F'){ - M = 'A' - 10; - }else if(c >= 'a' && c <= 'f'){ - M = 'a' - 10; - } - if(M){ - if(num & 0xf0000000){ // overflow - *N = 0xffffff; - return start; - } - num <<= 4; - num += c - M; - }else{ - break; - } - ++buf; - } - *N = num; - return (char*)buf; -} -// read octal number (without 0 prefix!) -static char *getoct(const char *buf, uint32_t *N){ - char *start = (char*)buf; - uint32_t num = 0; - while(*buf){ - char c = *buf; - if(c < '0' || c > '7'){ - break; - } - if(num & 0xe0000000){ // overflow - *N = 0xffffff; - return start; - } - num <<= 3; - num += c - '0'; - ++buf; - } - *N = num; - return (char*)buf; -} -// read binary number (without b prefix!) -static char *getbin(const char *buf, uint32_t *N){ - char *start = (char*)buf; - uint32_t num = 0; - while(*buf){ - char c = *buf; - if(c < '0' || c > '1'){ - break; - } - if(num & 0x80000000){ // overflow - *N = 0xffffff; - return start; - } - num <<= 1; - if(c == '1') num |= 1; - ++buf; - } - *N = num; - return (char*)buf; -} - -/** - * @brief getnum - read uint32_t from string (dec, hex or bin: 127, 0x7f, 0b1111111) - * @param buf - buffer with number and so on - * @param N - the number read - * @return pointer to first non-number symbol in buf - * (if it is == buf, there's no number or if *N==0xffffffff there was overflow) - */ -char *getnum(const char *txt, uint32_t *N){ - char *nxt = NULL; - char *s = omit_spaces(txt); - if(*s == '0'){ // hex, oct or 0 - if(s[1] == 'x' || s[1] == 'X'){ // hex - nxt = gethex(s+2, N); - if(nxt == s+2) nxt = (char*)txt; - }else if(s[1] > '0'-1 && s[1] < '8'){ // oct - nxt = getoct(s+1, N); - if(nxt == s+1) nxt = (char*)txt; - }else{ // 0 - nxt = s+1; - *N = 0; - } - }else if(*s == 'b' || *s == 'B'){ - nxt = getbin(s+1, N); - if(nxt == s+1) nxt = (char*)txt; - }else{ - nxt = getdec(s, N); - if(nxt == s) nxt = (char*)txt; - } - return nxt; -} - -const char* helpmsg = - "'0/1' - screen off/on\n" - "'2,3' - select font\n" - "'A' - get ADC values\n" - "'B' - start/stop rainBow\n" - "'b' - start/stop Balls\n" - "'C' - clear screen with given color\n" - "'F' - set foreground color\n" - "'G' - get 100 random numbers\n" - "'f' - get FPS\n" - "'R' - software reset\n" - "'W' - test watchdog\n" - "'Zz' -start/stop counting ms\n" - "Any text - put text @ screen\n" -; - -const char *parse_cmd(const char *buf){ - uint32_t N; - if(buf[1] == '\n'){ // one symbol commands - switch(*buf){ - case '0': - ScreenOFF(); - return "OFF\n"; - break; - case '1': - ScreenON(); - return "ON\n"; - break; - case '2': - if(choose_font(FONT14)) return "Font14\n"; - return "err\n"; - break; - case '3': - if(choose_font(FONT16)) return "Font16\n"; - return "err\n"; - break; - case 'A': - USB_send("Tsens="); USB_send(u2str(getADCval(0))); - USB_send("\nVref="); USB_send(u2str(getADCval(1))); - USB_send("\nRand="); USB_send(u2str(getRand())); - USB_send("\n"); - return NULL; - break; - case 'B': - if(rainbow){ - rainbow = 0; - return "Stop rainbow\n"; - }else{ - rainbow = 1; - return "Start rainbow\n"; - } - break; - case 'b': - if(balls){ - balls = 0; - return "Stop balls\n"; - }else{ - balls_init(); - balls = 1; - return "Start balls\n"; - } - case 'f': - if(SCREEN_RELAX == getScreenState()) return "Screen is inactive\n"; - USB_send("FPS="); - USB_send(u2str(getFPS())); - USB_send("\n"); - return NULL; - break; - case 'G': - /*USB_send(u2str(Tms)); USB_send("\n"); - for(int i=0; i < 1000; ++i) getRand(); - USB_send(u2str(Tms)); USB_send("\n");*/ - for(int i = 0; i < 100; ++i){ - USB_send(u2str(getRand())); - USB_send("\n"); - } - return NULL; - break; - case 'R': - USB_send("Soft reset\n"); - NVIC_SystemReset(); - break; - case 'W': - USB_send("Wait for reboot\n"); - while(1){nop();}; - break; - case 'Z': - countms = 1; - return "Start\n"; - break; - case 'z': - countms = 0; - return "Stop\n"; - break; - default: - return helpmsg; - } - return NULL; - }else{ - switch(*buf){ - case 'C': - if(getnum(buf+1, &N)){ - ScreenOFF(); - setBGcolor(N); - ClearScreen(); - ScreenON(); - return "Background color\n"; - } - return "Wrong color\n"; - break; - case 'F': - if(getnum(buf+1, &N)){ - setFGcolor(N); - return "Foreground color\n"; - } - return "Wrong color\n"; - break; - default: - ScreenOFF(); - ClearScreen(); - PutStringAt(1, curfont->height + 3, buf); - ScreenON(); - } - return buf; - } - return NULL; -} - -// return string with number `val` -char *u2str(uint32_t val){ - static char strbuf[11]; - char *bufptr = &strbuf[10]; - *bufptr = 0; - if(!val){ - *(--bufptr) = '0'; - }else{ - while(val){ - *(--bufptr) = val % 10 + '0'; - val /= 10; - } - } - return bufptr; -} diff --git a/F1-nolib/RGB_LED_Screen/proto.c b/F1-nolib/RGB_LED_Screen/proto.c new file mode 120000 index 0000000..ef1f2e9 --- /dev/null +++ b/F1-nolib/RGB_LED_Screen/proto.c @@ -0,0 +1 @@ +/home/eddy/Yandex.Disk/Projects/mytakepic/.hg/wcache/checklink-target \ No newline at end of file diff --git a/F1-nolib/SI7005_HTU21D/si7005.bin b/F1-nolib/SI7005_HTU21D/si7005.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/SPI/SPI.bin b/F1-nolib/SPI/SPI.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/SevenCDCs/cdcacmcore.bin b/F1-nolib/SevenCDCs/cdcacmcore.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/Tetris/TETRIS.bin b/F1-nolib/Tetris/TETRIS.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/Tetris/getrand b/F1-nolib/Tetris/getrand old mode 100755 new mode 100644 diff --git a/F1-nolib/Tetris/main.c b/F1-nolib/Tetris/main.c deleted file mode 100644 index 0513d46..0000000 --- a/F1-nolib/Tetris/main.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * This file is part of the TETRIS project. - * Copyright 2021 Edward V. Emelianov . - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "adcrandom.h" -#include "arkanoid.h" -#include "balls.h" -#include "buttons.h" -#include "fonts.h" -#include "hardware.h" -#include "menu.h" -#include "proto.h" -#include "screen.h" -#include "snake.h" -#include "tetris.h" -#include "usb.h" -#include "usb_lib.h" - -// timeout for autosleep (30s) -#define AUTOSLEEP_TMOUT (30000) - -volatile uint32_t Tms = 0; -uint8_t balls = 0; - -enum{ - STATE_MENU, - STATE_SNAKE, - STATE_TETRIS, - STATE_ARKANOID, - STATE_SLEEP, - STATE_GAMEOVER -} curstate = STATE_SLEEP; - -/* Called when systick fires */ -void sys_tick_handler(void){ - ++Tms; -} - -#define USBBUFSZ (127) -// usb getline -static char *get_USB(){ - static char tmpbuf[USBBUFSZ+1], *curptr = tmpbuf; - static int rest = USBBUFSZ; - int x = USB_receive(curptr); - curptr[x] = 0; - if(!x) return NULL; - if(curptr[x-1] == '\n'){ - curptr = tmpbuf; - rest = USBBUFSZ; - return tmpbuf; - } - curptr += x; rest -= x; - if(rest <= 0){ // buffer overflow - curptr = tmpbuf; - rest = USBBUFSZ; - USB_send("USB buffer overflow\n"); - } - return NULL; -} - -static void process_menu(){ - switch(menu_activated()){ - case MENU_SLEEP: - USB_send("Select 'Sleep'\n"); - ScreenOFF(); - curstate = STATE_SLEEP; - break; - case MENU_BALLS: - USB_send("Select 'Balls'\n"); - if(balls){ - balls = 0; - }else{ - curstate = STATE_SLEEP; - balls_init(); - balls = 1; - } - break; - case MENU_SNAKE: - USB_send("Select 'Snake'\n"); - snake_init(); - curstate = STATE_SNAKE; - break; - case MENU_TETRIS: - USB_send("Select 'Tetris'\n"); - tetris_init(); - curstate = STATE_TETRIS; - break; - case MENU_ARKANOID: - USB_send("Select 'Arkanoid'\n"); - arkanoid_init(); - curstate = STATE_ARKANOID; - default: - break; - } -} - -static void gotomenu(){ - curstate = STATE_MENU; - clear_events(); - show_menu(); -} - -int main(void){ - uint32_t lastT = 0; - sysreset(); - StartHSE(); - SysTick_Config(72000); - RCC->CSR |= RCC_CSR_RMVF; // remove reset flags - - hw_setup(); - USBPU_OFF(); - adc_setup(); - USB_setup(); - //iwdg_setup(); - USBPU_ON(); - - keyevent evt; - while(1){ - if(Tms - lastT > 499){ - LED_blink(LED0); - lastT = Tms; - } - IWDG->KR = IWDG_REFRESH; - if(balls) process_balls(); - process_keys(); - switch(curstate){ - case STATE_SLEEP: - if(keystate(KEY_M, &evt) && evt == EVT_RELEASE){ - USB_send("Activate menu\n"); - gotomenu(); - } - break; - case STATE_MENU: - process_menu(); - if(Tms - lastUnsleep > AUTOSLEEP_TMOUT){ - USB_send("Autosleep\n"); - ScreenOFF(); - curstate = STATE_SLEEP; - } - break; - case STATE_SNAKE: - if(!snake_proces()){ - show_gameover(); - curstate = STATE_GAMEOVER; - } - break; - case STATE_TETRIS: - if(!tetris_process()){ - show_gameover(); - curstate = STATE_GAMEOVER; - } - break; - case STATE_ARKANOID: - if(!arkanoid_process()){ - show_gameover(); - curstate = STATE_GAMEOVER; - } - break; - case STATE_GAMEOVER: // show gameover screen - if(keystate(KEY_M, &evt) && evt == EVT_RELEASE){ - gotomenu(); - }else if(Tms - lastUnsleep > AUTOSLEEP_TMOUT){ - USB_send("Autosleep\n"); - ScreenOFF(); - curstate = STATE_SLEEP; - } - break; - } - - usb_proc(); - char *txt; const char *ans; - if((txt = get_USB())){ - ans = parse_cmd(txt); - if(ans) USB_send(ans); - } - } - return 0; -} - diff --git a/F1-nolib/Tetris/main.c b/F1-nolib/Tetris/main.c new file mode 120000 index 0000000..ef1f2e9 --- /dev/null +++ b/F1-nolib/Tetris/main.c @@ -0,0 +1 @@ +/home/eddy/Yandex.Disk/Projects/mytakepic/.hg/wcache/checklink-target \ No newline at end of file diff --git a/F1-nolib/USB_HID/usbhid103.bin b/F1-nolib/USB_HID/usbhid103.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/chronometer/chrono.bin b/F1-nolib/chronometer/chrono.bin old mode 100644 new mode 100755 diff --git a/F1-nolib/chronometer_v2/chrono.bin b/F1-nolib/chronometer_v2/chrono.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/chronometer_v3/chrono.bin b/F1-nolib/chronometer_v3/chrono.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/inc/cm/core_cmFunc.h b/F1-nolib/inc/cm/core_cmFunc.h index a1bd88c..bdc54e6 100644 --- a/F1-nolib/inc/cm/core_cmFunc.h +++ b/F1-nolib/inc/cm/core_cmFunc.h @@ -453,7 +453,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void) */ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) { - __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp"); + __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack)); } diff --git a/F1-nolib/led_blink/blink.bin b/F1-nolib/led_blink/blink.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/pl2303_snippet/pl2303.bin b/F1-nolib/pl2303_snippet/pl2303.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/pl2303_snippet_naked/pl2303.bin b/F1-nolib/pl2303_snippet_naked/pl2303.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/pwmdmatest/pwmtest.bin b/F1-nolib/pwmdmatest/pwmtest.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/pwmtest/pwmtest.bin b/F1-nolib/pwmtest/pwmtest.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/uart/uart.bin b/F1-nolib/uart/uart.bin old mode 100755 new mode 100644 diff --git a/F1-nolib/ws2815/ws2815.bin b/F1-nolib/ws2815/ws2815.bin old mode 100755 new mode 100644 diff --git a/F1/1_wire/onewire.bin b/F1/1_wire/onewire.bin old mode 100755 new mode 100644 diff --git a/F1/2.8TFT/dma_gpio.bin b/F1/2.8TFT/dma_gpio.bin old mode 100755 new mode 100644 diff --git a/F1/DMA_GPIO/dma_gpio.bin b/F1/DMA_GPIO/dma_gpio.bin old mode 100755 new mode 100644 diff --git a/F1/GPIO_TIM/tim_gpio.bin b/F1/GPIO_TIM/tim_gpio.bin old mode 100755 new mode 100644 diff --git a/F1/GPS+ultrasonic/timelapse.bin b/F1/GPS+ultrasonic/timelapse.bin old mode 100755 new mode 100644 diff --git a/F1/GPS/GPS.bin b/F1/GPS/GPS.bin old mode 100755 new mode 100644 diff --git a/F1/Jeep_generator/jeep_generator.bin b/F1/Jeep_generator/jeep_generator.bin old mode 100755 new mode 100644 diff --git a/F1/Timelapse_keyboard/timelapse.bin b/F1/Timelapse_keyboard/timelapse.bin old mode 100755 new mode 100644 diff --git a/F1/Timelapse_keyboard_only_lasers/timelapse.bin b/F1/Timelapse_keyboard_only_lasers/timelapse.bin old mode 100755 new mode 100644 diff --git a/F1/USBCDC_template/usb_cdc_simple.bin b/F1/USBCDC_template/usb_cdc_simple.bin old mode 100755 new mode 100644 diff --git a/F1/canon_lens/canon_lens.bin b/F1/canon_lens/canon_lens.bin old mode 100755 new mode 100644 diff --git a/F1/distance_meters/ultrasonic.bin b/F1/distance_meters/ultrasonic.bin old mode 100755 new mode 100644 diff --git a/F1/hid_mouse_keyboard/usbhid.bin b/F1/hid_mouse_keyboard/usbhid.bin old mode 100755 new mode 100644 diff --git a/F1/keyboard_snippet/keyboard.bin b/F1/keyboard_snippet/keyboard.bin old mode 100755 new mode 100644 diff --git a/F1/matrix_keyboard/matrkeyb.bin b/F1/matrix_keyboard/matrkeyb.bin old mode 100755 new mode 100644 diff --git a/F1/nokia5110/nokia5110.bin b/F1/nokia5110/nokia5110.bin old mode 100755 new mode 100644 diff --git a/F1/simple_cdc/usb_cdc_simple.bin b/F1/simple_cdc/usb_cdc_simple.bin old mode 100755 new mode 100644 diff --git a/F1/stepper_motion/usb_cdc_simple.bin b/F1/stepper_motion/usb_cdc_simple.bin old mode 100755 new mode 100644 diff --git a/F1/ultrasonic/ultrasonic.bin b/F1/ultrasonic/ultrasonic.bin old mode 100755 new mode 100644 diff --git a/F303-nolib/blink/blink.bin b/F303-nolib/blink/blink.bin old mode 100755 new mode 100644 diff --git a/F303-nolib/usart1/usart1.bin b/F303-nolib/usart1/usart1.bin old mode 100755 new mode 100644 diff --git a/F303-nolib/usarts/usart.bin b/F303-nolib/usarts/usart.bin old mode 100755 new mode 100644