ESPHome 2025.5.0
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
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, "we 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++,
125 this->get_name(), 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,
144 RING_BUFFER_SIZE, 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, " UART %s ...", this->get_channel_name());
271 ESP_LOGCONFIG(TAG, " Baud rate: %" PRIu32 " Bd", this->baud_rate_);
272 ESP_LOGCONFIG(TAG, " Data bits: %u", this->data_bits_);
273 ESP_LOGCONFIG(TAG, " Stop bits: %u", this->stop_bits_);
274 ESP_LOGCONFIG(TAG, " Parity: %s", p2s(this->parity_));
275}
276
278 // enable transmission and reception
279 this->reg(WKREG_SCR) = SCR_RXEN | SCR_TXEN;
280 // we reset and enable transmit and receive FIFO
282}
283
285 this->data_bits_ = 8; // always equal to 8 for WeiKai (cant be changed)
286 uint8_t lcr = 0;
287 if (this->stop_bits_ == 2)
288 lcr |= LCR_STPL;
289 switch (this->parity_) { // parity selection settings
291 lcr |= (LCR_PAEN | LCR_PAR_ODD);
292 break;
294 lcr |= (LCR_PAEN | LCR_PAR_EVEN);
295 break;
296 default:
297 break; // no parity 000x
298 }
299 this->reg(WKREG_LCR) = lcr; // write LCR
300 ESP_LOGV(TAG, " line config: %d data_bits, %d stop_bits, parity %s register [%s]", this->data_bits_,
301 this->stop_bits_, p2s(this->parity_), I2S2CS(lcr));
302}
303
305 if (this->baud_rate_ > this->parent_->crystal_ / 16) {
306 baud_rate_ = this->parent_->crystal_ / 16;
307 ESP_LOGE(TAG, " Requested baudrate too high for crystal=%" PRIu32 " Hz. Has been reduced to %" PRIu32 " Bd",
308 this->parent_->crystal_, this->baud_rate_);
309 };
310 uint16_t const val_int = this->parent_->crystal_ / (this->baud_rate_ * 16) - 1;
311 uint16_t val_dec = (this->parent_->crystal_ % (this->baud_rate_ * 16)) / (this->baud_rate_ * 16);
312 uint8_t const baud_high = (uint8_t) (val_int >> 8);
313 uint8_t const baud_low = (uint8_t) (val_int & 0xFF);
314 while (val_dec > 0x0A)
315 val_dec /= 0x0A;
316 uint8_t const baud_dec = (uint8_t) (val_dec);
317
318 this->parent_->page1_ = true; // switch to page 1
319 this->reg(WKREG_SPAGE) = 1;
320 this->reg(WKREG_BRH) = baud_high;
321 this->reg(WKREG_BRL) = baud_low;
322 this->reg(WKREG_BRD) = baud_dec;
323 this->parent_->page1_ = false; // switch back to page 0
324 this->reg(WKREG_SPAGE) = 0;
325
326 ESP_LOGV(TAG, " Crystal=%" PRId32 " baudrate=%" PRId32 " => registers [%d %d %d]", this->parent_->crystal_,
327 this->baud_rate_, baud_high, baud_low, baud_dec);
328}
329
331
333 size_t tfcnt = this->reg(WKREG_TFCNT);
334 if (tfcnt == 0) {
335 uint8_t const fsr = this->reg(WKREG_FSR);
336 if (fsr & FSR_TFFULL) {
337 ESP_LOGVV(TAG, "tx FIFO full FSR=%s", I2S2CS(fsr));
338 tfcnt = FIFO_SIZE;
339 }
340 }
341 ESP_LOGVV(TAG, "tx FIFO contains %d bytes", tfcnt);
342 return tfcnt;
343}
344
346 size_t available = this->reg(WKREG_RFCNT);
347 uint8_t const fsr = this->reg(WKREG_FSR);
348 if (fsr & (FSR_RFOE | FSR_RFLB | FSR_RFFE | FSR_RFPE)) {
349 if (fsr & FSR_RFOE)
350 ESP_LOGE(TAG, "Receive data overflow FSR=%s", I2S2CS(fsr));
351 if (fsr & FSR_RFLB)
352 ESP_LOGE(TAG, "Receive line break FSR=%s", I2S2CS(fsr));
353 if (fsr & FSR_RFFE)
354 ESP_LOGE(TAG, "Receive frame error FSR=%s", I2S2CS(fsr));
355 if (fsr & FSR_RFPE)
356 ESP_LOGE(TAG, "Receive parity error FSR=%s", I2S2CS(fsr));
357 }
358 if ((available == 0) && (fsr & FSR_RFDAT)) {
359 // here we should be very careful because we can have something like this:
360 // - at time t0 we read RFCNT=0 because nothing yet received
361 // - at time t0+delta we might read FIFO not empty because one byte has just been received
362 // - so to be sure we need to do another read of RFCNT and if it is still zero -> buffer full
363 available = this->reg(WKREG_RFCNT);
364 if (available == 0) { // still zero ?
365 ESP_LOGV(TAG, "rx FIFO is full FSR=%s", I2S2CS(fsr));
367 }
368 }
369 ESP_LOGVV(TAG, "rx FIFO contain %d bytes - FSR status=%s", available, I2S2CS(fsr));
370 return available;
371}
372
374 // to check if we channel is up we write to the LCR W/R register
375 // note that this will put a break on the tx line for few ms
376 WeikaiRegister &lcr = this->reg(WKREG_LCR);
377 lcr = 0x3F;
378 uint8_t val = lcr;
379 if (val != 0x3F) {
380 ESP_LOGE(TAG, "R/W of register failed expected 0x3F received 0x%02X", val);
381 return true;
382 }
383 lcr = 0;
384 val = lcr;
385 if (val != 0x00) {
386 ESP_LOGE(TAG, "R/W of register failed expected 0x00 received 0x%02X", val);
387 return true;
388 }
389 return false;
390}
391
392bool WeikaiChannel::peek_byte(uint8_t *buffer) {
393 auto available = this->receive_buffer_.count();
394 if (!available)
396 return this->receive_buffer_.peek(*buffer);
397}
398
400 size_t available = this->receive_buffer_.count();
401 if (!available)
403 return available;
404}
405
406bool WeikaiChannel::read_array(uint8_t *buffer, size_t length) {
407 bool status = true;
408 auto available = this->receive_buffer_.count();
409 if (length > available) {
410 ESP_LOGW(TAG, "read_array: buffer underflow requested %d bytes only %d bytes available...", length, available);
412 status = false;
413 }
414 // retrieve the bytes from ring buffer
415 for (size_t i = 0; i < length; i++) {
416 this->receive_buffer_.pop(buffer[i]);
417 }
418 ESP_LOGVV(TAG, "read_array(ch=%d buffer[0]=%02X, length=%d): status %s", this->channel_, *buffer, length,
419 status ? "OK" : "ERROR");
420 return status;
421}
422
423void WeikaiChannel::write_array(const uint8_t *buffer, size_t length) {
424 if (length > XFER_MAX_SIZE) {
425 ESP_LOGE(TAG, "Write_array: invalid call - requested %d bytes but max size %d ...", length, XFER_MAX_SIZE);
427 }
428 this->reg(0).write_fifo(const_cast<uint8_t *>(buffer), length);
429}
430
432 uint32_t const start_time = millis();
433 while (this->tx_fifo_is_not_empty_()) { // wait until buffer empty
434 if (millis() - start_time > 200) {
435 ESP_LOGW(TAG, "WARNING flush timeout - still %d bytes not sent after 200 ms...", this->tx_in_fifo_());
436 return;
437 }
438 yield(); // reschedule our thread to avoid blocking
439 }
440}
441
443 size_t to_transfer;
444 size_t free;
445 while ((to_transfer = this->rx_in_fifo_()) && (free = this->receive_buffer_.free())) {
446 // while bytes in fifo and some room in the buffer we transfer
447 if (to_transfer > XFER_MAX_SIZE)
448 to_transfer = XFER_MAX_SIZE; // we can only do so much
449 if (to_transfer > free)
450 to_transfer = free; // we'll do the rest next time
451 if (to_transfer) {
452 uint8_t data[to_transfer];
453 this->reg(0).read_fifo(data, to_transfer);
454 for (size_t i = 0; i < to_transfer; i++)
455 this->receive_buffer_.push(data[i]);
456 }
457 } // while work to do
458 return to_transfer;
459}
460
462// TEST COMPONENT
463//
464#ifdef TEST_COMPONENT
467
471class Increment {
472 public:
474 Increment() : i_(0) {}
478 uint8_t operator()() { return i_++; }
479
480 private:
481 uint8_t i_;
482};
483
486void print_buffer(std::vector<uint8_t> buffer) {
487 char hex_buffer[100];
488 hex_buffer[(3 * 32) + 1] = 0;
489 for (size_t i = 0; i < buffer.size(); i++) {
490 snprintf(&hex_buffer[3 * (i % 32)], sizeof(hex_buffer), "%02X ", buffer[i]);
491 if (i % 32 == 31)
492 ESP_LOGI(TAG, " %s", hex_buffer);
493 }
494 if (buffer.size() % 32) {
495 // null terminate if incomplete line
496 hex_buffer[3 * (buffer.size() % 32) + 1] = 0;
497 ESP_LOGI(TAG, " %s", hex_buffer);
498 }
499}
500
503 auto start_exec = micros();
504 std::vector<uint8_t> output_buffer(XFER_MAX_SIZE);
505 generate(output_buffer.begin(), output_buffer.end(), Increment()); // fill with incrementing number
506 size_t to_send = RING_BUFFER_SIZE;
507 while (to_send) {
508 this->write_array(&output_buffer[0], XFER_MAX_SIZE); // we send the buffer
509 this->flush();
510 to_send -= XFER_MAX_SIZE;
511 }
512 ESP_LOGV(TAG, "%s => sent %d bytes - exec time %d µs ...", message, RING_BUFFER_SIZE, micros() - start_exec);
513}
514
517 auto start_exec = micros();
518 bool status = true;
519 size_t received = 0;
520 std::vector<uint8_t> buffer(RING_BUFFER_SIZE);
521
522 // we wait until we have received all the bytes
523 uint32_t const start_time = millis();
524 status = true;
525 while (received < RING_BUFFER_SIZE) {
526 while (XFER_MAX_SIZE > this->available()) {
527 this->xfer_fifo_to_buffer_();
528 if (millis() - start_time > 1500) {
529 ESP_LOGE(TAG, "uart_receive_test_() timeout: only %d bytes received...", this->available());
530 break;
531 }
532 yield(); // reschedule our thread to avoid blocking
533 }
534 status = this->read_array(&buffer[received], XFER_MAX_SIZE) && status;
535 received += XFER_MAX_SIZE;
536 }
537
538 uint8_t peek_value = 0;
539 this->peek_byte(&peek_value);
540 if (peek_value != 0) {
541 ESP_LOGE(TAG, "Peek first byte value error...");
542 status = false;
543 }
544
545 for (size_t i = 0; i < RING_BUFFER_SIZE; i++) {
546 if (buffer[i] != i % XFER_MAX_SIZE) {
547 ESP_LOGE(TAG, "Read buffer contains error...b=%x i=%x", buffer[i], i % XFER_MAX_SIZE);
548 print_buffer(buffer);
549 status = false;
550 break;
551 }
552 }
553
554 ESP_LOGV(TAG, "%s => received %d bytes status %s - exec time %d µs ...", message, received, status ? "OK" : "ERROR",
555 micros() - start_exec);
556 return status;
557}
558
560#endif
561
562} // namespace weikai
563} // namespace esphome
uint8_t status
Definition bl0942.h:8
uint32_t component_state_
State of this component.
Definition component.h:288
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:431
void set_line_param_()
set the line parameters
Definition weikai.cpp:284
void set_baudrate_()
set the baud rate
Definition weikai.cpp:304
bool peek_byte(uint8_t *buffer) override
Reads the first byte in FIFO without removing it.
Definition weikai.cpp:392
size_t xfer_fifo_to_buffer_()
transfer bytes from the weikai internal FIFO to the buffer (if any)
Definition weikai.cpp:442
virtual bool check_channel_down()
check if channel is alive
Definition weikai.cpp:373
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:406
void reset_fifo_()
reset the weikai internal FIFO
Definition weikai.cpp:277
bool tx_fifo_is_not_empty_()
test if transmit buffer is not empty in the status register (optimization)
Definition weikai.cpp:330
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:345
int available() override
Returns the number of bytes in the receive buffer.
Definition weikai.cpp:399
size_t tx_in_fifo_()
Returns the number of bytes in the transmit fifo.
Definition weikai.cpp:332
void write_array(const uint8_t *buffer, size_t length) override
Writes a specified number of bytes to a serial port.
Definition weikai.cpp:423
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:516
void uart_send_test_(char *message)
Test the write_array() method.
Definition weikai.cpp:502
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
const uint32_t COMPONENT_STATE_MASK
Definition component.cpp:32
const uint32_t COMPONENT_STATE_LOOP
Definition component.cpp:35
void IRAM_ATTR HOT yield()
Definition core.cpp:26
uint32_t IRAM_ATTR HOT micros()
Definition core.cpp:29
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:28
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:27
uint16_t length
Definition tt21100.cpp:0
WeiKai component family - classes declaration.