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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * lcd.c
  3. *
  4. * Copyright (c) 2023 - 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 <string.h>
  20. #include "hardware/i2c.h"
  21. #include "ssd1306.h"
  22. #include "git.h"
  23. #include "config.h"
  24. #include "hw_id.h"
  25. #include "log.h"
  26. #include "lcd.h"
  27. #define LCD_I2C_ADDR 0x3C
  28. static i2c_inst_t *gpio_inst_i2c = i2c1;
  29. static const uint gpio_num_i2c[2] = { 14, 15 };
  30. static ssd1306_t lcd = {0};
  31. static bool found = false;
  32. void lcd_init(void) {
  33. i2c_init(gpio_inst_i2c, 2UL * 1000UL * 1000UL);
  34. for (uint i = 0; i < sizeof(gpio_num_i2c) / sizeof(gpio_num_i2c[0]); i++) {
  35. gpio_set_function(gpio_num_i2c[i], GPIO_FUNC_I2C);
  36. gpio_pull_up(gpio_num_i2c[i]);
  37. }
  38. found = ssd1306_init(&lcd, LCD_WIDTH, LCD_HEIGHT, LCD_I2C_ADDR, gpio_inst_i2c);
  39. if (found) {
  40. debug("SSD1306 OLED is connected");
  41. } else {
  42. debug("No SSD1306 OLED found!");
  43. }
  44. }
  45. void lcd_splash_version(void) {
  46. if (!found) {
  47. return;
  48. }
  49. ssd1306_clear(&lcd);
  50. ssd1306_draw_string(&lcd, 0, 0, 2,
  51. "Dispensy");
  52. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1, 1,
  53. "Release: " VERSION_STR);
  54. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + FONT_HEIGHT + 1, 1,
  55. __DATE__ " " __TIME__);
  56. if (git_IsPopulated()) {
  57. const char *hash = git_CommitSHA1();
  58. char short_hash[6 + 7 + 6 + 1] = {0};
  59. memcpy(short_hash, "Hash: ", 6);
  60. memcpy(short_hash + 6, hash, 7);
  61. if (git_AnyUncommittedChanges()) {
  62. memcpy(short_hash + 6 + 7, " dirty", 6);
  63. }
  64. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
  65. short_hash);
  66. } else {
  67. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
  68. "No Git Repo");
  69. }
  70. char hw_id_str[42] = {0};
  71. snprintf(hw_id_str, sizeof(hw_id_str) - 1,
  72. "HW type=%X id=%X", hw_type(), hw_id());
  73. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 3, 1,
  74. hw_id_str);
  75. ssd1306_show(&lcd);
  76. }
  77. void lcd_bye(void) {
  78. ssd1306_clear(&lcd);
  79. ssd1306_draw_string(&lcd, 6, 5, 3, " Boot-");
  80. ssd1306_draw_string(&lcd, 8, LCD_HEIGHT / 2 + 5, 3, "loader");
  81. ssd1306_show(&lcd);
  82. }