mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 11:54:30 +03:00
add Canon managing device KiCAD schematic & PCB
This commit is contained in:
79
F1:F103/Canon_managing_device/main.c
Normal file
79
F1:F103/Canon_managing_device/main.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of the canonmanage project.
|
||||
* Copyright 2022 Edward V. Emelianov <edward.emelianoff@gmail.com>.
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "canon.h"
|
||||
#include "hardware.h"
|
||||
#include "proto.h"
|
||||
#include "spi.h"
|
||||
#include "usb.h"
|
||||
|
||||
#define USBBUFSZ 127
|
||||
|
||||
volatile uint32_t Tms = 0;
|
||||
|
||||
void sys_tick_handler(void){
|
||||
++Tms;
|
||||
}
|
||||
|
||||
// usb getline
|
||||
char *get_USB(){
|
||||
static char tmpbuf[USBBUFSZ+1], *curptr = tmpbuf;
|
||||
static int rest = USBBUFSZ;
|
||||
uint8_t x = USB_receive(curptr);
|
||||
if(!x) return NULL;
|
||||
curptr[x] = 0;
|
||||
if(curptr[x-1] == '\n'){
|
||||
curptr = tmpbuf;
|
||||
rest = USBBUFSZ;
|
||||
return tmpbuf;
|
||||
}
|
||||
curptr += x; rest -= x;
|
||||
if(rest <= 0){ // buffer overflow
|
||||
curptr = tmpbuf;
|
||||
rest = USBBUFSZ;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void){
|
||||
sysreset();
|
||||
StartHSE();
|
||||
SysTick_Config(72000);
|
||||
hw_setup();
|
||||
USB_setup();
|
||||
spi_setup();
|
||||
canon_init();
|
||||
|
||||
uint32_t ctr = Tms, SPIctr = Tms;
|
||||
while(1){
|
||||
if(Tms - ctr > 499){
|
||||
ctr = Tms;
|
||||
LED_blink(LED0);
|
||||
}
|
||||
char *txt = NULL;
|
||||
usb_proc();
|
||||
if((txt = get_USB())){
|
||||
const char *ans = parse_cmd(txt);
|
||||
if(ans) USB_send(ans);
|
||||
}
|
||||
if(Tms != SPIctr){ // not more than once per 1ms
|
||||
SPIctr = Tms;
|
||||
canon_proc();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user