| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #include <stdint.h>
- #include <stddef.h>
- #include <stdbool.h>
- #include <cx/chlcd.h>
- #include <cx/chlcd/__helper.h>
- chlcd_error_t chlcd_hd44780_direct_sender_init(void *self_pointer) {
- chlcd_hd44780_direct_connector_t *self
- = (chlcd_hd44780_direct_connector_t *) self_pointer;
- __R(chlcd_pin_set_output(self->e));
- __R(chlcd_pin_set_output(self->rs));
- __R(chlcd_pin_set_output(self->d4));
- __R(chlcd_pin_set_output(self->d5));
- __R(chlcd_pin_set_output(self->d6));
- __R(chlcd_pin_set_output(self->d7));
- __R(chlcd_pin_write(self->d7, false));
- __R(chlcd_pin_write(self->d6, false));
- __R(chlcd_pin_write(self->d5, false));
- __R(chlcd_pin_write(self->d4, false));
- __R(chlcd_pin_write(self->rs, false));
- __R(chlcd_pin_write(self->e, false));
-
- return CHLCD_SUCCESS;
- }
- chlcd_error_t __chlcd_hd44780_direct_sender_send_half_byte(
- chlcd_hd44780_direct_connector_t *self,
- uint8_t content,
- bool is_command
- ) {
- __R(chlcd_pin_write(self->d7, (content & 0b10000000)));
- __R(chlcd_pin_write(self->d6, (content & 0b01000000)));
- __R(chlcd_pin_write(self->d5, (content & 0b00100000)));
- __R(chlcd_pin_write(self->d4, (content & 0b00010000)));
- __R(chlcd_pin_write(self->rs, !is_command));
- __R(chlcd_pin_write(self->e, true));
- __R(chlcd_sleep_us(2000));
- __R(chlcd_pin_write(self->e, false));
- __R(chlcd_sleep_us(2000));
- return CHLCD_SUCCESS;
- }
- chlcd_error_t chlcd_hd44780_direct_sender(
- void *self_pointer,
- chlcd_data_t content,
- bool is_command,
- bool is_half_word
- ) {
- chlcd_hd44780_direct_connector_t *self
- = (chlcd_hd44780_direct_connector_t *) self_pointer;
- if (!is_half_word) {
- __R(__chlcd_hd44780_direct_sender_send_half_byte(
- self,
- content,
- is_command
- ));
- }
- content = content << 4;
- __R(__chlcd_hd44780_direct_sender_send_half_byte(
- self,
- content,
- is_command
- ));
- return CHLCD_SUCCESS;
- }
|