No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lcd.c 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * lcd.c
  3. *
  4. * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdio.h>
  19. #include <stdint.h>
  20. #include <string.h>
  21. #include "pico/stdlib.h"
  22. #include "hardware/i2c.h"
  23. #include "ssd1306.h"
  24. #include "logo.h"
  25. #include "main.h"
  26. #include "lcd.h"
  27. static i2c_inst_t *gpio_i2c_proto = i2c0;
  28. static const uint gpio_num_proto[2] = { 0, 1 };
  29. static i2c_inst_t *gpio_i2c_v2 = i2c0;
  30. static const uint gpio_num_v2[2] = { 16, 17 };
  31. #define LCD_ADDR 0x3C
  32. static ssd1306_t disp;
  33. void lcd_init(void) {
  34. if (hw_type == HW_PROTOTYPE) {
  35. i2c_init(gpio_i2c_proto, 1000 * 1000);
  36. for (uint i = 0; i < sizeof(gpio_num_proto) / sizeof(gpio_num_proto[0]); i++) {
  37. gpio_set_function(gpio_num_proto[i], GPIO_FUNC_I2C);
  38. gpio_pull_up(gpio_num_proto[i]);
  39. }
  40. disp.external_vcc = false;
  41. ssd1306_init(&disp, LCD_WIDTH, LCD_HEIGHT, LCD_ADDR, gpio_i2c_proto);
  42. } else if (hw_type == HW_V2) {
  43. i2c_init(gpio_i2c_v2, 1000 * 1000);
  44. for (uint i = 0; i < sizeof(gpio_num_v2) / sizeof(gpio_num_v2[0]); i++) {
  45. gpio_set_function(gpio_num_v2[i], GPIO_FUNC_I2C);
  46. gpio_pull_up(gpio_num_v2[i]);
  47. }
  48. disp.external_vcc = false;
  49. ssd1306_init(&disp, LCD_WIDTH, LCD_HEIGHT, LCD_ADDR, gpio_i2c_v2);
  50. }
  51. ssd1306_clear(&disp);
  52. for (uint y = 0; y < LOGO_HEIGHT; y++) {
  53. for (uint x = 0; x < LOGO_WIDTH; x++) {
  54. const uint pos = y * LOGO_WIDTH + x;
  55. const uint bit = 7 - (pos % 8);
  56. if (logo_data[pos / 8] & (1 << bit)) {
  57. ssd1306_draw_pixel(&disp, x, y);
  58. }
  59. }
  60. }
  61. ssd1306_show(&disp);
  62. }
  63. void lcd_draw(const char *mode, const char *val, const char *bat) {
  64. ssd1306_clear(&disp);
  65. ssd1306_draw_string(&disp, 0, 0, 2, mode);
  66. ssd1306_draw_string(&disp, 0, 20, 4, val);
  67. ssd1306_draw_string(&disp, 0, LCD_HEIGHT - 1 - 10, 1, bat);
  68. ssd1306_show(&disp);
  69. }