ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
weikai.cpp
Go to the documentation of this file.
1
5
6#include "weikai.h"
7
8namespace esphome {
9namespace weikai {
10
11static const char *const TAG = "weikai";
12
16inline std::string i2s(uint8_t val) { return std::bitset<8>(val).to_string(); }
18#define I2S2CS(val) (i2s(val).c_str())
19
23uint32_t elapsed_ms(uint32_t &last_time) {
24 uint32_t e = millis() - last_time;
25 last_time = millis();
26 return e;
27};
28
32const char *p2s(uart::UARTParityOptions parity) {
33 using namespace uart;
34 switch (parity) {
35 case UART_CONFIG_PARITY_NONE:
36 return "NONE";
37 case UART_CONFIG_PARITY_EVEN:
38 return "EVEN";
39 case UART_CONFIG_PARITY_ODD:
40 return "ODD";
41 default:
42 return "UNKNOWN";
43 }
44}
45
47void print_buffer(const uint8_t *data, size_t length) {
48 char hex_buffer[100];
49 hex_buffer[(3 * 32) + 1] = 0;
50 for (size_t i = 0; i < length; i++) {
51 snprintf(&hex_buffer[3 * (i % 32)], sizeof(hex_buffer), "%02X ", data[i]);
52 if (i % 32 == 31) {
53 ESP_LOGVV(TAG, " %s", hex_buffer);
54 }
55 }
56 if (length % 32) {
57 // null terminate if incomplete line
58 hex_buffer[3 * (length % 32) + 2] = 0;
59 ESP_LOGVV(TAG, " %s", hex_buffer);
60 }
61}
62
63static const char *const REG_TO_STR_P0[16] = {"GENA", "GRST", "GMUT", "SPAGE", "SCR", "LCR", "FCR", "SIER",
64 "SIFR", "TFCNT", "RFCNT", "FSR", "LSR", "FDAT", "FWCR", "RS485"};
65static const char *const REG_TO_STR_P1[16] = {"GENA", "GRST", "GMUT", "SPAGE", "BAUD1", "BAUD0", "PRES", "RFTL",
66 "TFTL", "FWTH", "FWTL", "XON1", "XOFF1", "SADR", "SAEN", "RTSDLY"};
67
68// method to print a register value as text: used in the log messages ...
69const char *reg_to_str(int reg, bool page1) {
70 if (reg == WKREG_GPDAT) {
71 return "GPDAT";
72 } else if (reg == WKREG_GPDIR) {
73 return "GPDIR";
74 } else {
75 return page1 ? REG_TO_STR_P1[reg & 0x0F] : REG_TO_STR_P0[reg & 0x0F];
76 }
77}
78
79enum RegType { REG = 0, FIFO = 1 };
80
82// The WeikaiRegister methods
85 write_reg(value);
86 return *this;
87}
88
90 value &= read_reg();
91 write_reg(value);
92 return *this;
93}
94
96 value |= read_reg();
97 write_reg(value);
98 return *this;
99}
100
102// The WeikaiComponent methods
105 if (!this->is_in_loop_state())
106 return;
107
108 // If there are some bytes in the receive FIFO we transfers them to the ring buffers
109 size_t transferred = 0;
110 for (auto *child : this->children_) {
111 // we look if some characters has been received in the fifo
112 transferred += child->xfer_fifo_to_buffer_();
113 }
114 if (transferred > 0) {
115 ESP_LOGV(TAG, "transferred %d bytes from fifo to buffer", transferred);
116 }
117
118#ifdef TEST_COMPONENT
119 static uint32_t loop_time = 0;
120 static uint32_t loop_count = 0;
121 uint32_t time = 0;
122
123 if (test_mode_ == 1) { // test component in loopback
124 ESP_LOGI(TAG, "Component loop %" PRIu32 " for %s : %" PRIu32 " ms since last call", loop_count++, this->get_name(),
125 millis() - loop_time);
126 loop_time = millis();
127 char message[64];
128 elapsed_ms(time); // set time to now
129 for (int i = 0; i < this->children_.size(); i++) {
130 if (i != ((loop_count - 1) % this->children_.size())) // we do only one per loop
131 continue;
132 snprintf(message, sizeof(message), "%s:%s", this->get_name(), children_[i]->get_channel_name());
133 children_[i]->uart_send_test_(message);
134 uint32_t const start_time = millis();
135 while (children_[i]->tx_fifo_is_not_empty_()) { // wait until buffer empty
136 if (millis() - start_time > 1500) {
137 ESP_LOGE(TAG, "timeout while flushing - %d bytes left in buffer", children_[i]->tx_in_fifo_());
138 break;
139 }
140 yield(); // reschedule our thread to avoid blocking
141 }
142 bool status = children_[i]->uart_receive_test_(message);
143 ESP_LOGI(TAG, "Test %s => send/received %u bytes %s - execution time %" PRIu32 " ms", message, RING_BUFFER_SIZE,
144 status ? "correctly" : "with error", elapsed_ms(time));
145 }
146 }
147
148 if (this->test_mode_ == 2) { // test component in echo mode
149 for (auto *child : this->children_) {
150 uint8_t data = 0;
151 if (child->available()) {
152 child->read_byte(&data);
153 ESP_LOGI(TAG, "echo mode: read -> send %02X", data);
154 child->write_byte(data);
155 }
156 }
157 }
158 if (test_mode_ == 3) {
160 }
161
162 if (test_mode_ == 4) {
164 }
165#endif
166}
167
168#if defined(TEST_COMPONENT)
170 static bool init_input{false};
171 static uint8_t state{0};
172 uint8_t value;
173 if (!init_input) {
174 init_input = true;
175 // set all pins in input mode
176 this->reg(WKREG_GPDIR, 0) = 0x00;
177 ESP_LOGI(TAG, "initializing all pins to input mode");
178 state = this->reg(WKREG_GPDAT, 0);
179 ESP_LOGI(TAG, "initial input data state = %02X (%s)", state, I2S2CS(state));
180 }
181 value = this->reg(WKREG_GPDAT, 0);
182 if (value != state) {
183 ESP_LOGI(TAG, "Input data changed from %02X to %02X (%s)", state, value, I2S2CS(value));
184 state = value;
185 }
186}
187
189 static bool init_output{false};
190 static uint8_t state{0};
191 if (!init_output) {
192 init_output = true;
193 // set all pins in output mode
194 this->reg(WKREG_GPDIR, 0) = 0xFF;
195 ESP_LOGI(TAG, "initializing all pins to output mode");
196 this->reg(WKREG_GPDAT, 0) = state;
197 ESP_LOGI(TAG, "setting all outputs to 0");
198 }
199 state = ~state;
200 this->reg(WKREG_GPDAT, 0) = state;
201 ESP_LOGI(TAG, "Flipping all outputs to %02X (%s)", state, I2S2CS(state));
202 delay(100); // NOLINT
203}
204#endif
205
207// The WeikaiGPIOPin methods
210 this->input_state_ = this->reg(WKREG_GPDAT, 0);
211 ESP_LOGVV(TAG, "reading input pin %u = %u in_state %s", pin, this->input_state_ & (1 << pin), I2S2CS(input_state_));
212 return this->input_state_ & (1 << pin);
213}
214
215void WeikaiComponent::write_pin_val_(uint8_t pin, bool value) {
216 if (value) {
217 this->output_state_ |= (1 << pin);
218 } else {
219 this->output_state_ &= ~(1 << pin);
220 }
221 ESP_LOGVV(TAG, "writing output pin %d with %d out_state %s", pin, uint8_t(value), I2S2CS(this->output_state_));
222 this->reg(WKREG_GPDAT, 0) = this->output_state_;
223}
224
226 if (flags == gpio::FLAG_INPUT) {
227 this->pin_config_ &= ~(1 << pin); // clear bit (input mode)
228 } else {
229 if (flags == gpio::FLAG_OUTPUT) {
230 this->pin_config_ |= 1 << pin; // set bit (output mode)
231 } else {
232 ESP_LOGE(TAG, "pin %d direction invalid", pin);
233 }
234 }
235 ESP_LOGVV(TAG, "setting pin %d direction to %d pin_config=%s", pin, flags, I2S2CS(this->pin_config_));
236 this->reg(WKREG_GPDIR, 0) = this->pin_config_; // TODO check ~
237}
238
240 ESP_LOGCONFIG(TAG, "Setting GPIO pin %d mode to %s", this->pin_,
241 flags_ == gpio::FLAG_INPUT ? "Input"
242 : this->flags_ == gpio::FLAG_OUTPUT ? "Output"
243 : "NOT SPECIFIED");
244 // ESP_LOGCONFIG(TAG, "Setting GPIO pins mode to '%s' %02X", I2S2CS(this->flags_), this->flags_);
245 this->pin_mode(this->flags_);
246}
247
248std::string WeikaiGPIOPin::dump_summary() const {
249 char buffer[32];
250 snprintf(buffer, sizeof(buffer), "%u via WeiKai %s", this->pin_, this->parent_->get_name());
251 return buffer;
252}
253
255// The WeikaiChannel methods
258 ESP_LOGCONFIG(TAG, " Setting up UART %s:%s", this->parent_->get_name(), this->get_channel_name());
259 // we enable transmit and receive on this channel
260 if (this->check_channel_down()) {
261 ESP_LOGCONFIG(TAG, " Error channel %s not working", this->get_channel_name());
262 }
263 this->reset_fifo_();
264 this->receive_buffer_.clear();
265 this->set_line_param_();
266 this->set_baudrate_();
267}
268
270 ESP_LOGCONFIG(TAG,
271 " UART %s\n"
272 " Baud rate: %" PRIu32 " Bd\n"
273 " Data bits: %u\n"
274 " Stop bits: %u\n"
275 " Parity: %s",
276 this->get_channel_name(), this->baud_rate_, this->data_bits_, this->stop_bits_, p2s(this->parity_));
277}
278
280 // enable transmission and reception
281 this->reg(WKREG_SCR) = SCR_RXEN | SCR_TXEN;
282 // we reset and enable transmit and receive FIFO
284}
285
287 this->data_bits_ = 8; // always equal to 8 for WeiKai (cant be changed)
288 uint8_t lcr = 0;
289 if (this->stop_bits_ == 2)
290 lcr |= LCR_STPL;
291 switch (this->parity_) { // parity selection settings
293 lcr |= (LCR_PAEN | LCR_PAR_ODD);
294 break;
296 lcr |= (LCR_PAEN | LCR_PAR_EVEN);
297 break;
298 default:
299 break; // no parity 000x
300 }
301 this->reg(WKREG_LCR) = lcr; // write LCR
302 ESP_LOGV(TAG, " line config: %d data_bits, %d stop_bits, parity %s register [%s]", this->data_bits_,
303 this->stop_bits_, p2s(this->parity_), I2S2CS(lcr));
304}
305
307 if (this->baud_rate_ > this->parent_->crystal_ / 16) {
308 baud_rate_ = this->parent_->crystal_ / 16;
309 ESP_LOGE(TAG, " Requested baudrate too high for crystal=%" PRIu32 " Hz. Has been reduced to %" PRIu32 " Bd",
310 this->parent_->crystal_, this->baud_rate_);
311 };
312 uint16_t const val_int = this->parent_->crystal_ / (this->baud_rate_ * 16) - 1;
313 uint16_t val_dec = (this->parent_->crystal_ % (this->baud_rate_ * 16)) / (this->baud_rate_ * 16);
314 uint8_t const baud_high = (uint8_t) (val_int >> 8);
315 uint8_t const baud_low = (uint8_t) (val_int & 0xFF);
316 while (val_dec > 0x0A)
317 val_dec /= 0x0A;
318 uint8_t const baud_dec = (uint8_t) (val_dec);
319
320 this->parent_->page1_ = true; // switch to page 1
321 this->reg(WKREG_SPAGE) = 1;
322 this->reg(WKREG_BRH) = baud_high;
323 this->reg(WKREG_BRL) = baud_low;
324 this->reg(WKREG_BRD) = baud_dec;
325 this->parent_->page1_ = false; // switch back to page 0
326 this->reg(WKREG_SPAGE) = 0;
327
328 ESP_LOGV(TAG, " Crystal=%" PRId32 " baudrate=%" PRId32 " => registers [%d %d %d]", this->parent_->crystal_,
329 this->baud_rate_, baud_high, baud_low, baud_dec);
330}
331
333
335 size_t tfcnt = this->reg(WKREG_TFCNT);
336 if (tfcnt == 0) {
337 uint8_t const fsr = this->reg(WKREG_FSR);
338 if (fsr & FSR_TFFULL) {
339 ESP_LOGVV(TAG, "tx FIFO full FSR=%s", I2S2CS(fsr));
340 tfcnt = FIFO_SIZE;
341 }
342 }
343 ESP_LOGVV(TAG, "tx FIFO contains %d bytes", tfcnt);
344 return tfcnt;
345}
346
348 size_t available = this->reg(WKREG_RFCNT);
349 uint8_t const fsr = this->reg(WKREG_FSR);
350 if (fsr & (FSR_RFOE | FSR_RFLB | FSR_RFFE | FSR_RFPE)) {
351 if (fsr & FSR_RFOE)
352 ESP_LOGE(TAG, "Receive data overflow FSR=%s", I2S2CS(fsr));
353 if (fsr & FSR_RFLB)
354 ESP_LOGE(TAG, "Receive line break FSR=%s", I2S2CS(fsr));
355 if (fsr & FSR_RFFE)
356 ESP_LOGE(TAG, "Receive frame error FSR=%s", I2S2CS(fsr));
357 if (fsr & FSR_RFPE)
358 ESP_LOGE(TAG, "Receive parity error FSR=%s", I2S2CS(fsr));
359 }
360 if ((available == 0) && (fsr & FSR_RFDAT)) {
361 // here we should be very careful because we can have something like this:
362 // - at time t0 we read RFCNT=0 because nothing yet received
363 // - at time t0+delta we might read FIFO not empty because one byte has just been received
364 // - so to be sure we need to do another read of RFCNT and if it is still zero -> buffer full
365 available = this->reg(WKREG_RFCNT);
366 if (available == 0) { // still zero ?
367 ESP_LOGV(TAG, "rx FIFO is full FSR=%s", I2S2CS(fsr));
369 }
370 }
371 ESP_LOGVV(TAG, "rx FIFO contain %d bytes - FSR status=%s", available, I2S2CS(fsr));
372 return available;
373}
374
376 // to check if we channel is up we write to the LCR W/R register
377 // note that this will put a break on the tx line for few ms
378 WeikaiRegister &lcr = this->reg(WKREG_LCR);
379 lcr = 0x3F;
380 uint8_t val = lcr;
381 if (val != 0x3F) {
382 ESP_LOGE(TAG, "R/W of register failed expected 0x3F received 0x%02X", val);
383 return true;
384 }
385 lcr = 0;
386 val = lcr;
387 if (val != 0x00) {
388 ESP_LOGE(TAG, "R/W of register failed expected 0x00 received 0x%02X", val);
389 return true;
390 }
391 return false;
392}
393
394bool WeikaiChannel::peek_byte(uint8_t *buffer) {
395 auto available = this->receive_buffer_.count();
396 if (!available)
398 return this->receive_buffer_.peek(*buffer);
399}
400
402 size_t available = this->receive_buffer_.count();
403 if (!available)
405 return available;
406}
407
408bool WeikaiChannel::read_array(uint8_t *buffer, size_t length) {
409 bool status = true;
410 auto available = this->receive_buffer_.count();
411 if (length > available) {
412 ESP_LOGW(TAG, "read_array: buffer underflow requested %d bytes only %d bytes available", length, available);
414 status = false;
415 }
416 // retrieve the bytes from ring buffer
417 for (size_t i = 0; i < length; i++) {
418 this->receive_buffer_.pop(buffer[i]);
419 }
420 ESP_LOGVV(TAG, "read_array(ch=%d buffer[0]=%02X, length=%d): status %s", this->channel_, *buffer, length,
421 status ? "OK" : "ERROR");
422 return status;
423}
424
425void WeikaiChannel::write_array(const uint8_t *buffer, size_t length) {
426 if (length > XFER_MAX_SIZE) {
427 ESP_LOGE(TAG, "Write_array: invalid call - requested %d bytes but max size %d", length, XFER_MAX_SIZE);
429 }
430 this->reg(0).write_fifo(const_cast<uint8_t *>(buffer), length);
431}
432
434 uint32_t const start_time = millis();
435 while (this->tx_fifo_is_not_empty_()) { // wait until buffer empty
436 if (millis() - start_time > 200) {
437 ESP_LOGW(TAG, "WARNING flush timeout - still %d bytes not sent after 200 ms", this->tx_in_fifo_());
438 return;
439 }
440 yield(); // reschedule our thread to avoid blocking
441 }
442}
443
445 size_t to_transfer;
446 size_t free;
447 while ((to_transfer = this->rx_in_fifo_()) && (free = this->receive_buffer_.free())) {
448 // while bytes in fifo and some room in the buffer we transfer
449 if (to_transfer > XFER_MAX_SIZE)
450 to_transfer = XFER_MAX_SIZE; // we can only do so much
451 if (to_transfer > free)
452 to_transfer = free; // we'll do the rest next time
453 if (to_transfer) {
454 uint8_t data[to_transfer];
455 this->reg(0).read_fifo(data, to_transfer);
456 for (size_t i = 0; i < to_transfer; i++)
457 this->receive_buffer_.push(data[i]);
458 }
459 } // while work to do
460 return to_transfer;
461}
462
464// TEST COMPONENT
465//
466#ifdef TEST_COMPONENT
469
473class Increment {
474 public:
476 Increment() : i_(0) {}
480 uint8_t operator()() { return i_++; }
481
482 private:
483 uint8_t i_;
484};
485
488void print_buffer(std::vector<uint8_t> buffer) {
489 char hex_buffer[100];
490 hex_buffer[(3 * 32) + 1] = 0;
491 for (size_t i = 0; i < buffer.size(); i++) {
492 snprintf(&hex_buffer[3 * (i % 32)], sizeof(hex_buffer), "%02X ", buffer[i]);
493 if (i % 32 == 31)
494 ESP_LOGI(TAG, " %s", hex_buffer);
495 }
496 if (buffer.size() % 32) {
497 // null terminate if incomplete line
498 hex_buffer[3 * (buffer.size() % 32) + 1] = 0;
499 ESP_LOGI(TAG, " %s", hex_buffer);
500 }
501}
502
505 auto start_exec = micros();
506 std::vector<uint8_t> output_buffer(XFER_MAX_SIZE);
507 generate(output_buffer.begin(), output_buffer.end(), Increment()); // fill with incrementing number
508 size_t to_send = RING_BUFFER_SIZE;
509 while (to_send) {
510 this->write_array(&output_buffer[0], XFER_MAX_SIZE); // we send the buffer
511 this->flush();
512 to_send -= XFER_MAX_SIZE;
513 }
514 ESP_LOGV(TAG, "%s => sent %d bytes - exec time %d µs", message, RING_BUFFER_SIZE, micros() - start_exec);
515}
516
519 auto start_exec = micros();
520 bool status = true;
521 size_t received = 0;
522 std::vector<uint8_t> buffer(RING_BUFFER_SIZE);
523
524 // we wait until we have received all the bytes
525 uint32_t const start_time = millis();
526 status = true;
527 while (received < RING_BUFFER_SIZE) {
528 while (XFER_MAX_SIZE > this->available()) {
529 this->xfer_fifo_to_buffer_();
530 if (millis() - start_time > 1500) {
531 ESP_LOGE(TAG, "uart_receive_test_() timeout: only %d bytes received", this->available());
532 break;
533 }
534 yield(); // reschedule our thread to avoid blocking
535 }
536 status = this->read_array(&buffer[received], XFER_MAX_SIZE) && status;
537 received += XFER_MAX_SIZE;
538 }
539
540 uint8_t peek_value = 0;
541 this->peek_byte(&peek_value);
542 if (peek_value != 0) {
543 ESP_LOGE(TAG, "Peek first byte value error");
544 status = false;
545 }
546
547 for (size_t i = 0; i < RING_BUFFER_SIZE; i++) {
548 if (buffer[i] != i % XFER_MAX_SIZE) {
549 ESP_LOGE(TAG, "Read buffer contains error b=%x i=%x", buffer[i], i % XFER_MAX_SIZE);
550 print_buffer(buffer);
551 status = false;
552 break;
553 }
554 }
555
556 ESP_LOGV(TAG, "%s => received %d bytes status %s - exec time %d µs", message, received, status ? "OK" : "ERROR",
557 micros() - start_exec);
558 return status;
559}
560
562#endif
563
564} // namespace weikai
565} // namespace esphome
uint8_t status
Definition bl0942.h:8
bool is_in_loop_state() const
Check if this component has completed setup and is in the loop state.
size_t free()
returns the number of free positions in the buffer
Definition weikai.h:111
bool push(const T item)
pushes an item at the tail of the fifo
Definition weikai.h:66
bool peek(T &item)
return the value of the item at fifo's head without removing it
Definition weikai.h:90
void clear()
clear the buffer content
Definition weikai.h:114
bool pop(T &item)
return and remove the item at head of the fifo
Definition weikai.h:78
size_t count()
return the number of item in the ring buffer
Definition weikai.h:107
virtual void dump_channel()
dump channel information
Definition weikai.cpp:269
virtual void setup_channel()
Setup the channel.
Definition weikai.cpp:257
WeikaiRegister & reg(uint8_t reg)
Factory method to create a WeikaiRegister proxy object.
Definition weikai.h:328
void flush() override
Flush the output fifo.
Definition weikai.cpp:433
void set_line_param_()
set the line parameters
Definition weikai.cpp:286
void set_baudrate_()
set the baud rate
Definition weikai.cpp:306
bool peek_byte(uint8_t *buffer) override
Reads the first byte in FIFO without removing it.
Definition weikai.cpp:394
size_t xfer_fifo_to_buffer_()
transfer bytes from the weikai internal FIFO to the buffer (if any)
Definition weikai.cpp:444
virtual bool check_channel_down()
check if channel is alive
Definition weikai.cpp:375
const char * get_channel_name()
Get the channel name.
Definition weikai.h:317
WeikaiComponent * parent_
our WK2168component parent
Definition weikai.h:438
WKRingBuffer< uint8_t, RING_BUFFER_SIZE > receive_buffer_
the buffer where we store temporarily the bytes received
Definition weikai.h:437
bool read_array(uint8_t *buffer, size_t length) override
Reads a specified number of bytes from a serial port.
Definition weikai.cpp:408
void reset_fifo_()
reset the weikai internal FIFO
Definition weikai.cpp:279
bool tx_fifo_is_not_empty_()
test if transmit buffer is not empty in the status register (optimization)
Definition weikai.cpp:332
uint8_t channel_
our Channel number
Definition weikai.h:439
size_t rx_in_fifo_()
Returns the number of bytes in the receive fifo.
Definition weikai.cpp:347
int available() override
Returns the number of bytes in the receive buffer.
Definition weikai.cpp:401
size_t tx_in_fifo_()
Returns the number of bytes in the transmit fifo.
Definition weikai.cpp:334
void write_array(const uint8_t *buffer, size_t length) override
Writes a specified number of bytes to a serial port.
Definition weikai.cpp:425
int test_mode_
test mode value (0 -> no tests)
Definition weikai.h:262
virtual WeikaiRegister & reg(uint8_t reg, uint8_t channel)=0
Factory method to create a Register object.
uint8_t input_state_
input pin states: 1 means HIGH, 0 means LOW
Definition weikai.h:260
uint32_t crystal_
crystal value;
Definition weikai.h:261
void write_pin_val_(uint8_t pin, bool value)
Helper method to write the value of a pin.
Definition weikai.cpp:215
bool read_pin_val_(uint8_t pin)
Helper method to read the value of a pin.
Definition weikai.cpp:209
uint8_t output_state_
output state: 1 means HIGH, 0 means LOW
Definition weikai.h:259
bool page1_
set to true when in "page1 mode"
Definition weikai.h:263
std::vector< WeikaiChannel * > children_
the list of WeikaiChannel UART children
Definition weikai.h:264
void loop() override
override the Component loop()
Definition weikai.cpp:104
void set_pin_direction_(uint8_t pin, gpio::Flags flags)
Helper method to set the pin mode of a pin.
Definition weikai.cpp:225
uint8_t pin_config_
pin config mask: 1 means OUTPUT, 0 means INPUT
Definition weikai.h:258
const char * get_name()
Get the name of the component.
Definition weikai.h:216
void pin_mode(gpio::Flags flags) override
Definition weikai.h:282
std::string dump_summary() const override
Definition weikai.cpp:248
WeikaiComponent * parent_
Definition weikai.h:287
WeikaiRegister objects acts as proxies to access remote register independently of the bus type.
Definition weikai.h:139
virtual void write_reg(uint8_t value)=0
writes the register
WeikaiRegister & operator|=(uint8_t value)
overloads the compound |= operator.
Definition weikai.cpp:95
WeikaiRegister & operator&=(uint8_t value)
overloads the compound &= operator.
Definition weikai.cpp:89
virtual void write_fifo(uint8_t *data, size_t length)=0
write an array of bytes to the transmitter fifo
WeikaiRegister & operator=(uint8_t value)
overloads the = operator.
Definition weikai.cpp:84
virtual uint8_t read_reg() const =0
reads the register
virtual void read_fifo(uint8_t *data, size_t length) const =0
read an array of bytes from the receiver fifo
bool state
Definition fan.h:0
constexpr uint8_t FSR_TFDAT
Transmitter FIFO count (0: empty, 1: not empty)
Definition wk_reg_def.h:253
constexpr uint8_t FCR_RFRST
Receiver FIFO reset.
Definition wk_reg_def.h:193
constexpr uint8_t FSR_RFPE
Receiver Parity Error (0: no PE, 1: PE)
Definition wk_reg_def.h:249
constexpr uint8_t WKREG_RFCNT
Receiver FIFO count - c0/c1 1010.
Definition wk_reg_def.h:219
constexpr uint8_t SCR_RXEN
receiving control (0: enable, 1: disable)
Definition wk_reg_def.h:145
constexpr uint8_t WKREG_FCR
FIFO Control Register - c0/c1 0110.
Definition wk_reg_def.h:185
constexpr uint8_t LCR_STPL
Stop length (0: 1 bit, 1: 2 bits)
Definition wk_reg_def.h:171
constexpr uint8_t FCR_TFRST
Transmitter FIFO reset.
Definition wk_reg_def.h:191
constexpr uint8_t SCR_TXEN
transmission control (0: enable, 1: disable)
Definition wk_reg_def.h:143
constexpr uint8_t FCR_TFEN
Transmitter FIFO enable.
Definition wk_reg_def.h:187
constexpr uint8_t FSR_RFOE
Receiver FIFO Overflow Error (0: no OE, 1: OE)
Definition wk_reg_def.h:243
constexpr uint8_t WKREG_FSR
FIFO Status Register - c0/c1 1011.
Definition wk_reg_def.h:241
constexpr uint8_t FCR_RFEN
Receiver FIFO enable.
Definition wk_reg_def.h:189
constexpr uint8_t FSR_RFFE
Receiver FIFO Frame Error (0: no FE, 1: FE)
Definition wk_reg_def.h:247
constexpr uint8_t LCR_PAR_ODD
Parity odd.
Definition wk_reg_def.h:165
constexpr uint8_t FSR_RFDAT
Receiver FIFO count (0: empty, 1: not empty)
Definition wk_reg_def.h:251
constexpr uint8_t WKREG_TFCNT
Transmitter FIFO Count - c0/c1 1001.
Definition wk_reg_def.h:209
constexpr uint8_t FSR_TFFULL
Transmitter FIFO full (0: not full, 1: full)
Definition wk_reg_def.h:255
constexpr uint8_t WKREG_LCR
Line Configuration Register - c0/c1 0101.
Definition wk_reg_def.h:159
constexpr uint8_t WKREG_SCR
Serial Control Register - c0/c1 0100.
Definition wk_reg_def.h:141
constexpr uint8_t FSR_RFLB
Receiver FIFO Line Break (0: no LB, 1: LB)
Definition wk_reg_def.h:245
constexpr uint8_t LCR_PAR_EVEN
Parity even.
Definition wk_reg_def.h:167
constexpr uint8_t LCR_PAEN
Parity enable (0: no check, 1: check)
Definition wk_reg_def.h:161
constexpr uint8_t WKREG_SPAGE
Global Page register c0/c1 0011.
Definition wk_reg_def.h:127
constexpr uint8_t WKREG_BRH
Baud rate configuration register: high byte - c0/c1 0100.
Definition wk_reg_def.h:280
constexpr uint8_t WKREG_BRL
Baud rate configuration register: low byte - c0/c1 0101.
Definition wk_reg_def.h:290
constexpr uint8_t WKREG_BRD
Baud rate configuration register decimal part - c0/c1 0110.
Definition wk_reg_def.h:293
bool uart_receive_test_(char *message)
Test the read_array() method.
Definition weikai.cpp:518
void uart_send_test_(char *message)
Test the write_array() method.
Definition weikai.cpp:504
constexpr uint8_t WKREG_GPDIR
Global GPIO direction register - 10 0001.
Definition wk_reg_def.h:85
constexpr uint8_t WKREG_GPDAT
Global GPIO data register - 11 0001.
Definition wk_reg_def.h:99
mopeka_std_values val[4]
@ FLAG_OUTPUT
Definition gpio.h:19
@ FLAG_INPUT
Definition gpio.h:18
constexpr size_t XFER_MAX_SIZE
XFER_MAX_SIZE defines the maximum number of bytes allowed during one transfer.
Definition weikai.h:34
constexpr size_t RING_BUFFER_SIZE
size of the ring buffer set to size of the FIFO
Definition weikai.h:43
const char * reg_to_str(int reg, bool page1)
Definition weikai.cpp:69
const char * p2s(uart::UARTParityOptions parity)
Converts the parity enum value to a C string.
Definition weikai.cpp:32
constexpr size_t FIFO_SIZE
size of the internal WeiKai FIFO
Definition weikai.h:40
std::string i2s(uint8_t val)
convert an int to binary representation as C++ std::string
Definition weikai.cpp:16
void print_buffer(const uint8_t *data, size_t length)
Display a buffer in hexadecimal format (32 hex values / line) for debug.
Definition weikai.cpp:47
uint32_t elapsed_ms(uint32_t &last_time)
measure the time elapsed between two calls
Definition weikai.cpp:23
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT yield()
Definition core.cpp:27
uint32_t IRAM_ATTR HOT micros()
Definition core.cpp:30
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:29
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:28
uint16_t length
Definition tt21100.cpp:0
WeiKai component family - classes declaration.