42#define CHIP_NAME "Sitronix ST7920"
43#define MANUFACTURER_NAME "Sitronix"
44#define SUPPLY_VOLTAGE_MIN 2.7f
45#define SUPPLY_VOLTAGE_MAX 4.5f
46#define MAX_CURRENT 0.45f
47#define TEMPERATURE_MIN -30.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
66#define ST7920_CMD_BASIC_DISPLAY_CLEAR 0x01
67#define ST7920_CMD_BASIC_RETURN_HOME 0x02
68#define ST7920_CMD_BASIC_ENTRY_MODE_SET 0x04
69#define ST7920_CMD_BASIC_DISPLAY_CONTROL 0x08
70#define ST7920_CMD_BASIC_CURSOR_DISPLAY_CONTROL 0x10
71#define ST7920_CMD_BASIC_FUNCTION_SET 0x20
72#define ST7920_CMD_BASIC_SET_CGRAM 0x40
73#define ST7920_CMD_BASIC_SET_DDRAM 0x80
74#define ST7920_CMD_EXT_STANFBY 0x01
75#define ST7920_CMD_EXT_SCROLL_RAM_ADDRESS_SELECT 0x02
76#define ST7920_CMD_EXT_REVERSE 0x04
77#define ST7920_CMD_EXT_FUNCTION_SET 0x20
78#define ST7920_CMD_EXT_SET_SCROLL_ADDRESS 0x40
79#define ST7920_CMD_EXT_SET_GRAPHIC_DISPLAY_RAM_ADDRESS 0x80
90static uint8_t a_st7920_serial_write(
st7920_handle_t *handle, uint8_t data)
95 for (i = 0; i < 8; i++)
97 if ((data & 0x80) != 0)
143static uint8_t a_st7920_write_byte(
st7920_handle_t *handle, uint8_t rw, uint8_t rs, uint8_t data, uint32_t us)
160 res = a_st7920_serial_write(handle, reg);
170 reg |= ((data >> 4) & 0xF) << 4;
171 res = a_st7920_serial_write(handle, reg);
181 reg |= ((data >> 0) & 0xF) << 4;
182 res = a_st7920_serial_write(handle, reg);
228 handle->
debug_print(
"st7920: cs_gpio_init is null.\n");
234 handle->
debug_print(
"st7920: cs_gpio_deinit is null.\n");
240 handle->
debug_print(
"st7920: cs_gpio_write is null.\n");
246 handle->
debug_print(
"st7920: sclk_gpio_init is null.\n");
252 handle->
debug_print(
"st7920: sclk_gpio_deinit is null.\n");
258 handle->
debug_print(
"st7920: sclk_gpio_write is null.\n");
264 handle->
debug_print(
"st7920: sid_gpio_init is null.\n");
270 handle->
debug_print(
"st7920: sid_gpio_deinit is null.\n");
276 handle->
debug_print(
"st7920: sid_gpio_write is null.\n");
282 handle->
debug_print(
"st7920: delay_ms is null.\n");
288 handle->
debug_print(
"st7920: delay_us is null.\n");
295 handle->
debug_print(
"st7920: cs gpio init failed.\n");
301 handle->
debug_print(
"st7920: sclk gpio init failed.\n");
308 handle->
debug_print(
"st7920: sid gpio init failed.\n");
315 for (i = 0; i < 8; i++)
317 for (j = 0; j < 64; j++)
319 handle->
gram[i][j] = 0;
352 handle->
debug_print(
"st7920: set function failed.\n");
360 handle->
debug_print(
"st7920: set display control failed.\n");
366 handle->
debug_print(
"st7920: cs gpio deinit failed.\n");
372 handle->
debug_print(
"st7920: sclk gpio deinit failed.\n");
378 handle->
debug_print(
"st7920: sid gpio deinit failed.\n");
416 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
435 handle->
gram[x / 16][y] |= 1 << (15 - (x % 16));
439 handle->
gram[x / 16][y] &= ~(1 << (15 - (x % 16)));
448 handle->
debug_print(
"st7920: set graphic address failed.\n");
457 handle->
debug_print(
"st7920: set graphic address failed.\n");
462 (uint8_t)((handle->
gram[x / 16][y % 64] >> 8) & 0xFF),
465 handle->
debug_print(
"st7920: write data failed.\n");
470 (uint8_t)((handle->
gram[x / 16][y % 64] >> 0) & 0xFF),
473 handle->
debug_print(
"st7920: write data failed.\n");
510 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
526 *data = (handle->
gram[x / 16][y] >> (15 - (x % 16))) & 0x01;
563 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
599 handle->
debug_print(
"st7920: set ddram address failed.\n");
604 for (i = 0; str[i] != 0; i++)
609 handle->
debug_print(
"st7920: write data failed.\n");
626static void a_st7920_draw_point(
st7920_handle_t *handle, uint8_t x, uint8_t y, uint8_t data)
630 handle->
gram[x / 16][y] |= 1 << (15 - (x % 16));
634 handle->
gram[x / 16][y] &= ~(1 << (15 - (x % 16)));
661 uint8_t pos_start, pos_end;
673 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
677 if ((left > 127) || (top > 63))
679 handle->
debug_print(
"st7920: left or top is invalid.\n");
683 if ((right > 127) || (bottom > 63))
685 handle->
debug_print(
"st7920: right or bottom is invalid.\n");
689 if ((left > right) || (top > bottom))
691 handle->
debug_print(
"st7920: left > right or top > bottom.\n");
696 for (x = left; x <= right; x++)
698 for (y = top; y <= bottom; y++)
700 a_st7920_draw_point(handle, x, y, color);
706 for (i = pos_start; i < pos_end; i++)
712 handle->
debug_print(
"st7920: set graphic address failed.\n");
720 handle->
debug_print(
"st7920: set graphic address failed.\n");
724 for (j = 0; j < 8; j++)
727 (uint8_t)((handle->
gram[j][i % 64] >> 8) & 0xFF),
730 handle->
debug_print(
"st7920: write data failed.\n");
735 (uint8_t)((handle->
gram[j][i % 64] >> 0) & 0xFF),
738 handle->
debug_print(
"st7920: write data failed.\n");
744 for (i = pos_start; i < pos_end; i++)
750 handle->
debug_print(
"st7920: set graphic address failed.\n");
758 handle->
debug_print(
"st7920: set graphic address failed.\n");
762 for (j = 0; j < 8; j++)
765 (uint8_t)((handle->
gram[j][(i + 32) % 64] >> 8) & 0xFF),
768 handle->
debug_print(
"st7920: write data failed.\n");
773 (uint8_t)((handle->
gram[j][(i + 32) % 64] >> 0) & 0xFF),
776 handle->
debug_print(
"st7920: write data failed.\n");
809 uint8_t pos_start, pos_end;
821 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
825 if ((left > 127) || (top > 63))
827 handle->
debug_print(
"st7920: left or top is invalid.\n");
831 if ((right > 127) || (bottom > 63))
833 handle->
debug_print(
"st7920: right or bottom is invalid.\n");
837 if ((left > right) || (top > bottom))
839 handle->
debug_print(
"st7920: left > right or top > bottom.\n");
844 for (x = left; x <= right; x++)
846 for (y = top; y <= bottom; y++)
848 a_st7920_draw_point(handle, x, y, *img);
855 for (i = pos_start; i < pos_end; i++)
861 handle->
debug_print(
"st7920: set graphic address failed.\n");
869 handle->
debug_print(
"st7920: set graphic address failed.\n");
873 for (j = 0; j < 8; j++)
876 (uint8_t)((handle->
gram[j][i % 64] >> 8) & 0xFF),
879 handle->
debug_print(
"st7920: write data failed.\n");
884 (uint8_t)((handle->
gram[j][i % 64] >> 0) & 0xFF),
887 handle->
debug_print(
"st7920: write data failed.\n");
893 for (i = pos_start; i < pos_end; i++)
899 handle->
debug_print(
"st7920: set graphic address failed.\n");
907 handle->
debug_print(
"st7920: set graphic address failed.\n");
911 for (j = 0; j < 8; j++)
914 (uint8_t)((handle->
gram[j][(i + 32) % 64] >> 8) & 0xFF),
917 handle->
debug_print(
"st7920: write data failed.\n");
922 (uint8_t)((handle->
gram[j][(i + 32) % 64] >> 0) & 0xFF),
925 handle->
debug_print(
"st7920: write data failed.\n");
958 uint8_t pos_start, pos_end;
970 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
974 if ((left > 127) || (top > 63))
976 handle->
debug_print(
"st7920: left or top is invalid.\n");
980 if ((right > 127) || (bottom > 63))
982 handle->
debug_print(
"st7920: right or bottom is invalid.\n");
986 if ((left > right) || (top > bottom))
988 handle->
debug_print(
"st7920: left > right or top > bottom.\n");
993 for (x = left; x <= right; x++)
995 for (y = top; y <= bottom; y++)
1001 l = (x - left) * (bottom - top + 1) + (y - top);
1004 if (((img[m] >> (7 - n)) & 0x01) != 0)
1006 a_st7920_draw_point(handle, x, y, 0xFF);
1010 a_st7920_draw_point(handle, x, y, 0x00);
1017 for (i = pos_start; i < pos_end; i++)
1023 handle->
debug_print(
"st7920: set graphic address failed.\n");
1031 handle->
debug_print(
"st7920: set graphic address failed.\n");
1035 for (j = 0; j < 8; j++)
1038 (uint8_t)((handle->
gram[j][i % 64] >> 8) & 0xFF),
1041 handle->
debug_print(
"st7920: write data failed.\n");
1046 (uint8_t)((handle->
gram[j][i % 64] >> 0) & 0xFF),
1049 handle->
debug_print(
"st7920: write data failed.\n");
1055 for (i = pos_start; i < pos_end; i++)
1061 handle->
debug_print(
"st7920: set graphic address failed.\n");
1069 handle->
debug_print(
"st7920: set graphic address failed.\n");
1073 for (j = 0; j < 8; j++)
1076 (uint8_t)((handle->
gram[j][(i + 32) % 64] >> 8) & 0xFF),
1079 handle->
debug_print(
"st7920: write data failed.\n");
1084 (uint8_t)((handle->
gram[j][(i + 32) % 64] >> 0) & 0xFF),
1087 handle->
debug_print(
"st7920: write data failed.\n");
1120 for (i = 0; i < 8; i++)
1122 for (j = 0; j < 64; j++)
1124 handle->
gram[i][j] = 0;
1133 handle->
debug_print(
"st7920: display clear failed.\n");
1140 for (i = 0; i < 64; i++)
1146 handle->
debug_print(
"st7920: set graphic address failed.\n");
1154 handle->
debug_print(
"st7920: set graphic address failed.\n");
1158 for (j = 0; j < 8; j++)
1163 handle->
debug_print(
"st7920: write data failed.\n");
1170 handle->
debug_print(
"st7920: write data failed.\n");
1176 for (i = 0; i < 64; i++)
1182 handle->
debug_print(
"st7920: set graphic address failed.\n");
1190 handle->
debug_print(
"st7920: set graphic address failed.\n");
1194 for (j = 0; j < 8; j++)
1199 handle->
debug_print(
"st7920: write data failed.\n");
1206 handle->
debug_print(
"st7920: write data failed.\n");
1240 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1248 handle->
debug_print(
"st7920: return home failed.\n");
1281 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1288 (mode << 1) | (shift << 0)),
1291 handle->
debug_print(
"st7920: set entry mode failed.\n");
1325 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1332 (cursor_on << 1) | (character_blink_on << 0)),
1335 handle->
debug_print(
"st7920: set display control failed.\n");
1367 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1374 ((mode & 0x3) << 2)),
1377 handle->
debug_print(
"st7920: set display shift mode failed.\n");
1412 handle->
debug_print(
"st7920: set function failed.\n");
1446 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1452 handle->
debug_print(
"st7920: addr is over 0x3F.\n");
1461 handle->
debug_print(
"st7920: set cgram address failed.\n");
1494 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1500 handle->
debug_print(
"st7920: addr is over 0x7F.\n");
1509 handle->
debug_print(
"st7920: set ddram address failed.\n");
1544 handle->
debug_print(
"st7920: this command must be run in basic command mode.\n");
1549 for (i = 0; i < len; i++)
1554 handle->
debug_print(
"st7920: write ram failed.\n");
1586 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
1594 handle->
debug_print(
"st7920: set standby failed.\n");
1626 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
1633 (enable & 0x01) << 0),
1636 handle->
debug_print(
"st7920: set vertical scroll failed.\n");
1668 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
1677 handle->
debug_print(
"st7920: set reverse line failed.\n");
1712 graphic_display_enable << 1),
1715 handle->
debug_print(
"st7920: set extended function failed.\n");
1749 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
1755 handle->
debug_print(
"st7920: addr is over 0x3F.\n");
1764 handle->
debug_print(
"st7920: set scroll address failed.\n");
1801 handle->
debug_print(
"st7920: this command must be run in extended command mode.\n");
1805 if (vertical_addr > 0x3F)
1807 handle->
debug_print(
"st7920: vertical_addr is over 0x3F.\n");
1811 if (horizontal_addr > 0xF)
1813 handle->
debug_print(
"st7920: horizontal_addr is over 0xF.\n");
1823 handle->
debug_print(
"st7920: set graphic address failed.\n");
1832 handle->
debug_print(
"st7920: set graphic address failed.\n");
1865 handle->
debug_print(
"st7920: write cmd failed.\n");
1898 handle->
debug_print(
"st7920: write data failed.\n");
#define ST7920_CMD_EXT_SET_SCROLL_ADDRESS
#define ST7920_CMD_BASIC_SET_DDRAM
#define SUPPLY_VOLTAGE_MAX
#define ST7920_WRITE
command type definition
#define ST7920_CMD_BASIC_DISPLAY_CLEAR
command definition
#define ST7920_CMD_BASIC_SET_CGRAM
#define ST7920_CMD
data type definition
#define ST7920_CMD_EXT_SCROLL_RAM_ADDRESS_SELECT
#define ST7920_CMD_EXT_SET_GRAPHIC_DISPLAY_RAM_ADDRESS
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define ST7920_CMD_BASIC_DISPLAY_CONTROL
#define ST7920_CMD_EXT_REVERSE
#define CHIP_NAME
chip information definition
#define ST7920_CMD_BASIC_FUNCTION_SET
#define ST7920_CMD_EXT_FUNCTION_SET
#define ST7920_CMD_BASIC_CURSOR_DISPLAY_CONTROL
#define ST7920_CMD_EXT_STANFBY
#define ST7920_CMD_BASIC_ENTRY_MODE_SET
#define ST7920_CMD_BASIC_RETURN_HOME
driver st7920 header file
uint8_t st7920_set_cgram_address(st7920_handle_t *handle, uint8_t addr)
set the cgram address
uint8_t st7920_info(st7920_info_t *info)
get chip's information
struct st7920_info_s st7920_info_t
st7920 information structure definition
uint8_t st7920_set_function(st7920_handle_t *handle, st7920_interface_bus_bit_t bus_bit, st7920_command_mode_t mode)
set the function
st7920_bool_t
st7920 bool enumeration definition
uint8_t st7920_write_ram(st7920_handle_t *handle, uint8_t *data, uint8_t len)
write the ram
uint8_t st7920_display_clear(st7920_handle_t *handle)
clear the display
uint8_t st7920_set_entry_mode(st7920_handle_t *handle, st7920_display_shift_t shift, st7920_address_counter_mode_t mode)
set the entry mode
st7920_display_shift_t
st7920 display shift enumeration definition
#define ST7920_COMMAND_DATA_DELAY
st7920 command data delay definition
struct st7920_handle_s st7920_handle_t
st7920 handle structure definition
st7920_command_mode_t
st7920 command mode enumeration definition
uint8_t st7920_return_home(st7920_handle_t *handle)
return the home
st7920_address_counter_mode_t
st7920 address counter mode enumeration definition
st7920_display_shift_mode_t
st7920 display shift mode enumeration definition
uint8_t st7920_init(st7920_handle_t *handle)
initialize the chip
uint8_t st7920_deinit(st7920_handle_t *handle)
close the chip
uint8_t st7920_set_ddram_address(st7920_handle_t *handle, uint8_t addr)
set the ddram address
st7920_interface_bus_bit_t
st7920 interface bus bit enumeration definition
uint8_t st7920_set_display_control(st7920_handle_t *handle, st7920_bool_t display_on, st7920_bool_t cursor_on, st7920_bool_t character_blink_on)
set the display control
uint8_t st7920_write_string(st7920_handle_t *handle, uint8_t x, uint8_t y, char *str)
show a string
#define ST7920_COMMAND_CMD_DELAY
st7920 command cmd delay definition
uint8_t st7920_set_display_shift_mode(st7920_handle_t *handle, st7920_display_shift_mode_t mode)
set the display shift mode
uint8_t st7920_draw_compress_picture(st7920_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
draw a compressed picture
uint8_t st7920_set_standby(st7920_handle_t *handle)
terminate to the standby mode
uint8_t st7920_write_point(st7920_handle_t *handle, uint8_t x, uint8_t y, uint8_t data)
write a point
uint8_t st7920_set_reverse_line(st7920_handle_t *handle, st7920_reverse_line_t l)
set the reverse line
uint8_t st7920_set_vertical_scroll(st7920_handle_t *handle, st7920_bool_t enable)
set the vertical scroll
uint8_t st7920_set_extended_function(st7920_handle_t *handle, st7920_interface_bus_bit_t bus_bit, st7920_command_mode_t mode, st7920_bool_t graphic_display_enable)
set the extended function
st7920_reverse_line_t
st7920 reverse line enumeration definition
uint8_t st7920_fill_rect(st7920_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t color)
fill a rectangle
uint8_t st7920_draw_picture(st7920_handle_t *handle, uint8_t left, uint8_t top, uint8_t right, uint8_t bottom, uint8_t *img)
draw a picture
uint8_t st7920_set_graphic_address(st7920_handle_t *handle, uint8_t vertical_addr, uint8_t horizontal_addr)
set the graphic address
uint8_t st7920_read_point(st7920_handle_t *handle, uint8_t x, uint8_t y, uint8_t *data)
read a point
uint8_t st7920_set_scroll_address(st7920_handle_t *handle, uint8_t addr)
set the scroll address
uint8_t st7920_write_data(st7920_handle_t *handle, uint8_t data)
write data
uint8_t st7920_write_cmd(st7920_handle_t *handle, uint8_t cmd)
write command
uint8_t(* sid_gpio_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* sclk_gpio_write)(uint8_t value)
uint8_t(* sclk_gpio_deinit)(void)
uint8_t(* cs_gpio_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* sid_gpio_write)(uint8_t value)
void(* delay_us)(uint32_t us)
uint8_t(* cs_gpio_init)(void)
uint8_t(* sclk_gpio_init)(void)
uint8_t(* cs_gpio_write)(uint8_t value)
uint8_t(* sid_gpio_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v