Skip to content

Commit

Permalink
scrolling OLED display
Browse files Browse the repository at this point in the history
  • Loading branch information
n24bass committed Oct 3, 2017
1 parent fa1ee82 commit 89bbdbe
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 36 deletions.
2 changes: 1 addition & 1 deletion components/controls/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void controls_init(TaskFunction_t gpio_handler_task, const uint16_t usStackDepth

void controls_destroy()
{
gpio_isr_handler_remove(GPIO_NUM_0);
gpio_isr_handler_remove(GPIO_NUM_16);
vTaskDelete(gpio_task);
vQueueDelete(gpio_evt_queue);
// TODO: free gpio_handler_param_t params
Expand Down
6 changes: 6 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ menuconfig BT_SPEAKER_MODE
Web radio streaming will be unavailable.
depends on CLASSIC_BT_ENABLED

config SSD1306_6432
help
only for Web radio mode
bool "use SSD1306_6432"

endmenu

87 changes: 66 additions & 21 deletions main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@
#define I2C_EXAMPLE_MASTER_RX_BUF_DISABLE 0 /*!< I2C master do not need buffer */
#define I2C_EXAMPLE_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */


const static char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";

const static char http_t[] = "<html><head><title>ESP32 PCM5102A webradio</title></head><body><h1>Web radio station list</h1><ul>";
const static char http_t[] = "<html><head><title>ESP32 PCM5102A webradio</title></head><body><h1>ESP32 PCM5102A webradio</h1><h2>Station list</h2><ul>";
const static char http_e[] = "</ul><a href=\"P\">prev</a>&nbsp;<a href=\"N\">next</a></body></html>";

/* */
Expand Down Expand Up @@ -202,12 +201,64 @@ void erase_nvurl(int n) {

xSemaphoreHandle print_mux;

static char *surl = NULL;
static char ip[16];
static int x = 0;
static int l = 0;

#ifdef CONFIG_SSD1306_6432
#define XOFFSET 31
#define YOFFSET 32
#define WIDTH 64
#define HEIGHT 32
#else
#define WIDTH 128
#define HEIGHT 64
#define XOFFSET 0
#define YOFFSET 0
#endif

void oled_scroll(void) {
if (surl == NULL) return;
while (l) {
vTaskDelay(20/portTICK_RATE_MS);
}
int w = strlen(surl) * 7;
if (w <= WIDTH) return;

#ifdef CONFIG_SSD1306_6432
SSD1306_GotoXY(XOFFSET - x, YOFFSET + 10);
SSD1306_Puts(surl, &Font_7x10, SSD1306_COLOR_WHITE);
SSD1306_GotoXY(XOFFSET - x, YOFFSET + 20);
SSD1306_Puts(ip, &Font_7x10, SSD1306_COLOR_WHITE);
#else
SSD1306_GotoXY(2 - x, 37);
SSD1306_Puts(surl, &Font_7x10, SSD1306_COLOR_WHITE);
#endif

x++;
if (x > w) x = -WIDTH;
SSD1306_UpdateScreen();
}

void i2c_test(int mode)
{
char *url = get_url(); // play_url();
x = 0;
surl = url;

SSD1306_Fill(SSD1306_COLOR_BLACK); // clear screen

#ifdef CONFIG_SSD1306_6432
SSD1306_GotoXY(XOFFSET + 2, YOFFSET); // 31, 32);
SSD1306_Puts("ESP32PICO", &Font_7x10, SSD1306_COLOR_WHITE);
SSD1306_GotoXY(XOFFSET - x, YOFFSET + 10);
SSD1306_Puts(surl, &Font_7x10, SSD1306_COLOR_WHITE);
SSD1306_GotoXY(XOFFSET - x, YOFFSET + 20);
tcpip_adapter_ip_info_t ip_info;
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
strcpy(ip, ip4addr_ntoa(&ip_info.ip));
SSD1306_Puts(ip + 3, &Font_7x10, SSD1306_COLOR_WHITE);
#else
SSD1306_GotoXY(40, 4);
SSD1306_Puts("ESP32", &Font_11x18, SSD1306_COLOR_WHITE);

Expand Down Expand Up @@ -238,23 +289,13 @@ void i2c_test(int mode)
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
SSD1306_GotoXY(2, 53);
SSD1306_Puts("IP:", &Font_7x10, SSD1306_COLOR_WHITE);
SSD1306_Puts(ip4addr_ntoa(&ip_info.ip), &Font_7x10, SSD1306_COLOR_WHITE);
SSD1306_Puts(ip4addr_ntoa(&ip_info.ip), &Font_7x10, SSD1306_COLOR_WHITE);
#endif
#endif

/* Update screen, send changes to LCD */
SSD1306_UpdateScreen();

// while (1) {
// /* Invert pixels */
// SSD1306_ToggleInvert();

/* Update screen */
// SSD1306_UpdateScreen();

/* Make a little delay */
// vTaskDelay(50);
// }


l = 0;
}

/**
Expand Down Expand Up @@ -464,7 +505,7 @@ static void start_web_radio()
radio_config->url = get_url(); // play_url(); /* PLAY_URL; */

xTaskCreate(&http_server, "http_server", 2048, NULL, 5, NULL);
if (gpio_get_level(GPIO_NUM_16) == 0) {
if (gpio_get_level(GPIO_NUM_0) == 0) {
while (1)
vTaskDelay(200/portTICK_RATE_MS);
}
Expand Down Expand Up @@ -560,7 +601,7 @@ http_server_netconn_serve(struct netconn *conn)
get_nvurl(i, buf, length);
if (i == stno) netconn_write(conn, "<b>", 3, NETCONN_NOCOPY);
netconn_write(conn, buf, strlen(buf), NETCONN_NOCOPY);
if (i == stno) netconn_write(conn, "</b> - now playing", 24, NETCONN_NOCOPY);
if (i == stno) netconn_write(conn, "</b> - now playing", 18, NETCONN_NOCOPY);
netconn_write(conn, "</a></li>", 9, NETCONN_NOCOPY);
}
netconn_write(conn, http_e, sizeof(http_e)-1, NETCONN_NOCOPY);
Expand Down Expand Up @@ -624,6 +665,10 @@ void app_main()
#endif
ESP_LOGI(TAG, "RAM left %d", esp_get_free_heap_size());
// ESP_LOGI(TAG, "app_main stack: %d\n", uxTaskGetStackHighWaterMark(NULL));
while (1)
vTaskDelay(200/portTICK_RATE_MS);
while (1) {
vTaskDelay(40/portTICK_RATE_MS);
#ifdef CONFIG_SSD1306_6432
oled_scroll();
#endif
}
}
18 changes: 6 additions & 12 deletions main/ssd1306.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8];

/* Private SSD1306 structure */
typedef struct {
uint16_t CurrentX;
uint16_t CurrentY;
int16_t CurrentX;
int16_t CurrentY;
uint8_t Inverted;
uint8_t Initialized;
} SSD1306_t;
Expand Down Expand Up @@ -98,11 +98,8 @@ void SSD1306_Fill(SSD1306_COLOR_t color) {
memset(SSD1306_Buffer, (color == SSD1306_COLOR_BLACK) ? 0x00 : 0xFF, sizeof(SSD1306_Buffer));
}

void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color) {
if (
x >= SSD1306_WIDTH ||
y >= SSD1306_HEIGHT
) {
void SSD1306_DrawPixel(int16_t x, int16_t y, SSD1306_COLOR_t color) {
if (x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT || x < 0 || y < 0) {
/* Error */
return;
}
Expand All @@ -120,7 +117,7 @@ void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color) {
}
}

void SSD1306_GotoXY(uint16_t x, uint16_t y) {
void SSD1306_GotoXY(int16_t x, int16_t y) {
/* Set write pointers */
SSD1306.CurrentX = x;
SSD1306.CurrentY = y;
Expand All @@ -130,10 +127,7 @@ char SSD1306_Putc(char ch, FontDef_t* Font, SSD1306_COLOR_t color) {
uint32_t i, b, j;

/* Check available space in LCD */
if (
SSD1306_WIDTH <= (SSD1306.CurrentX + Font->FontWidth) ||
SSD1306_HEIGHT <= (SSD1306.CurrentY + Font->FontHeight)
) {
if (SSD1306_WIDTH <= SSD1306.CurrentX || SSD1306_HEIGHT <= SSD1306.CurrentY) {
/* Error */
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions main/ssd1306.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ void SSD1306_Fill(SSD1306_COLOR_t Color);
* @param color: Color to be used for screen fill. This parameter can be a value of @ref SSD1306_COLOR_t enumeration
* @retval None
*/
void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color);
void SSD1306_DrawPixel(int16_t x, int16_t y, SSD1306_COLOR_t color);

/**
* @brief Sets cursor pointer to desired location for strings
* @param x: X location. This parameter can be a value between 0 and SSD1306_WIDTH - 1
* @param y: Y location. This parameter can be a value between 0 and SSD1306_HEIGHT - 1
* @retval None
*/
void SSD1306_GotoXY(uint16_t x, uint16_t y);
void SSD1306_GotoXY(int16_t x, int16_t y);

/**
* @brief Puts character to internal RAM
Expand Down
2 changes: 2 additions & 0 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

CONFIG_ESP32_DEFAULT_CPU_FREQ_160=y
CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ=160

FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n

0 comments on commit 89bbdbe

Please sign in to comment.