59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#include "system.h"
|
|
#include "gpio.h"
|
|
#include "usart.h"
|
|
#include "print.h"
|
|
/*********************************************************************************
|
|
Sériový port na CH32V203F6P6 je příklad jak by z dokumentace člověka klepla pepka.
|
|
Podle DS to má jen jeden sériový port, ale vývody USART1 nejsou nijak vyvedeny
|
|
z pouzdra. Tak zkusíte USART2, a ejhle, ono to funguje.
|
|
**********************************************************************************/
|
|
#if 0
|
|
class TEST : public BaseLayer { // Testovací třída pro test příjmu - OK.
|
|
static constexpr unsigned buflen = 64u;
|
|
char buffer [buflen];
|
|
unsigned rx_index;
|
|
GpioClass & led;
|
|
public:
|
|
explicit TEST (GpioClass & io) noexcept : BaseLayer(), rx_index(0u), led(io) {}
|
|
uint32_t Up(const char * data, const uint32_t len) override {
|
|
for (unsigned n=0u; n<len; n++) {
|
|
const char c = data [n];
|
|
if (c == '\r') { // Enter
|
|
Down ("\r\n", 2);
|
|
Down (buffer, rx_index); // Vrátí obsah bufferu na novém řádku
|
|
Down ("\r\n", 2);
|
|
rx_index = 0u;
|
|
return 0;
|
|
}
|
|
buffer [rx_index] = c;
|
|
const bool b = rx_index & 1u;
|
|
led << b; // Po každém znaku změní stav
|
|
rx_index += 1u;
|
|
}
|
|
return len;
|
|
}
|
|
};
|
|
#endif
|
|
static constexpr unsigned timeout = 100'000;
|
|
static GpioClass led (GPIOB, 8);
|
|
static Usart serial (57600);
|
|
static Print cout;
|
|
//static TEST test (led);
|
|
|
|
int main () {
|
|
led << true;
|
|
delay_init();
|
|
//test += serial;
|
|
cout += serial;
|
|
int passcnt = 0;
|
|
for (;;) {
|
|
delay_us(timeout);
|
|
|
|
cout << "pass : " << passcnt << EOL;
|
|
const bool b = passcnt & 1;
|
|
led << b;
|
|
passcnt += 1;
|
|
|
|
}
|
|
return 0;
|
|
}
|