STM32H750VB_APPLE/lib/ewl1501aa/src/ewl1501aa.c

62 lines
2.1 KiB
C

#include "ewl1501aa.h"
#include <stddef.h>
#define EWL1501_ERR_CHECK(x) \
if (x != EWL1501AA_OK) return EWL1501AA_FAIL
static uint8_t ewl1501aa_init_param[] = {
0x01, 0x81, 0x9C, // Set contrast control
0x01, 0xA0, 0x53, // Set segment re-map
0x01, 0xA1, 0x00, // Set display start line
0x01, 0xA2, 0x00, // Set display offset
0x00, 0xA4, // Set normal display mode
0x01, 0xA8, 0x7F, // Set MUX ratio
0x01, 0xAB, 0x01, // Set enable internal VDD regulator mode
0x01, 0xB1, 0x31, // Set phase length of phase 1, phase 2
0x01, 0xB3, 0xF1, // Set ratio of dividing frequency & oscillation frequency
0x00, 0xB9, // Set gray scale table
0x01, 0xBC, 0x07, // Set pre-charge voltage
0x01, 0xBE, 0x07, // Set voltage VCOMH
0x02, 0x15, 0x00, 0x3F, // Set column address
0x02, 0x75, 0x00, 0x7F, // Set row address
};
static ewl1501aa_ret_t ewl1501aa_reset(ewl1501aa_t *ewl) {
if (ewl->cb.reset_cb != NULL) {
return ewl->cb.reset_cb(ewl->user_data);
}
return EWL1501AA_OK;
}
static ewl1501aa_ret_t ewl1501aa_init_seq(ewl1501aa_t *ewl) {
uint16_t seq_ptr = 0;
while (seq_ptr < sizeof(ewl1501aa_init_param)) {
EWL1501_ERR_CHECK(ewl->cb.write_cmd_cb(ewl->user_data, &ewl1501aa_init_param[seq_ptr + 1],
ewl1501aa_init_param[seq_ptr] + 1));
seq_ptr += ewl1501aa_init_param[seq_ptr] + 2;
}
return EWL1501AA_OK;
}
ewl1501aa_ret_t ewl1501aa_init(ewl1501aa_t *ewl) {
EWL1501_ERR_CHECK(ewl1501aa_reset(ewl));
EWL1501_ERR_CHECK(ewl1501aa_init_seq(ewl));
return EWL1501AA_OK;
}
ewl1501aa_ret_t ewl1501aa_upload(ewl1501aa_t *ewl, uint8_t *data) {
EWL1501_ERR_CHECK(ewl->cb.write_data_cb(ewl->user_data, data, 8192));
return EWL1501AA_OK;
}
ewl1501aa_ret_t ewl1501aa_power(ewl1501aa_t *ewl, uint8_t on) {
uint8_t cmd[2] = { 0xAE, 0x00 };
if(on) cmd[0] = 0xAF;
EWL1501_ERR_CHECK(ewl->cb.write_cmd_cb(ewl->user_data, cmd, 1));
return EWL1501AA_OK;
}