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

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