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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. void lcd_init(void) {
  30. i2c_init(gpio_inst_i2c, 2UL * 1000UL * 1000UL);
  31. for (uint i = 0; i < sizeof(gpio_num_i2c) / sizeof(gpio_num_i2c[0]); i++) {
  32. gpio_set_function(gpio_num_i2c[i], GPIO_FUNC_I2C);
  33. gpio_pull_up(gpio_num_i2c[i]);
  34. }
  35. ssd1306_init(&lcd, LCD_WIDTH, LCD_HEIGHT, LCD_I2C_ADDR, gpio_inst_i2c);
  36. }
  37. void lcd_splash(void) {
  38. ssd1306_clear(&lcd);
  39. ssd1306_draw_string(&lcd, 0, 0, 2,
  40. "Dispensy");
  41. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1, 1,
  42. "Release: " VERSION_STR);
  43. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + FONT_HEIGHT + 1, 1,
  44. __DATE__ " " __TIME__);
  45. if (git_IsPopulated()) {
  46. const char *hash = git_CommitSHA1();
  47. char short_hash[6 + 7 + 1] = {0};
  48. memcpy(short_hash, "Hash: ", 6);
  49. memcpy(short_hash + 6, hash, 7);
  50. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
  51. short_hash);
  52. if (git_AnyUncommittedChanges()) {
  53. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 3, 1,
  54. "Repo has changes!");
  55. }
  56. } else {
  57. ssd1306_draw_string(&lcd, 0, FONT_HEIGHT * 2 + 1 + (FONT_HEIGHT + 1) * 2, 1,
  58. "No Git Repo");
  59. }
  60. ssd1306_show(&lcd);
  61. }