Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blit #21

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Blit #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
build/
.cache/
34 changes: 2 additions & 32 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,2 @@
cmake_minimum_required(VERSION 3.13)

# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(ssd1306-example)

set(CMAKE_C_STANDARD 11)

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# rest of your project

add_executable(ssd1306-example
example.c ../ssd1306.c
)

target_include_directories(ssd1306-example
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../
)

target_link_libraries(ssd1306-example pico_stdlib hardware_i2c)

pico_enable_stdio_usb(ssd1306-example 1)
pico_enable_stdio_uart(ssd1306-example 0)

# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(ssd1306-example)

add_subdirectory(basic_example)
add_subdirectory(usb_cdc_example)
49 changes: 49 additions & 0 deletions example/basic_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.13)

# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(ssd1306-examples)

set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(USE_DMA_FOR_DISPLAY "Use the DMA engine to move the display buffer to the display" OFF)

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# rest of your project
add_subdirectory(../../src lib)
add_executable(ssd1306-example
example.c
)

target_include_directories(ssd1306-example
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/../../fonts
)

if(USE_DMA_FOR_DISPLAY)
message(STATUS "Using DMA")
target_compile_definitions(ssd1306-example
PUBLIC
SSD1306_USE_DMA
)
target_link_libraries(ssd1306-example
hardware_dma
)
endif(USE_DMA_FOR_DISPLAY)

target_link_libraries(ssd1306-example
pico_stdlib
hardware_i2c
ssd1306
ssd1306_widgets
)

pico_enable_stdio_usb(ssd1306-example 0)
pico_enable_stdio_uart(ssd1306-example 1)
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(ssd1306-example)

61 changes: 37 additions & 24 deletions example/example.c → example/basic_example/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
#include "bubblesstandard_font.h"
#include "crackers_font.h"
#include "BMSPA_font.h"
#include "font.h"

const uint8_t num_chars_per_disp[]={7,7,7,5};
const uint8_t *fonts[4]= {acme_font, bubblesstandard_font, crackers_font, BMSPA_font};
const uint8_t *fonts[] = {acme_font, bubblesstandard_font, crackers_font, BMSPA_font};

#define SLEEPTIME 30
#ifdef SSD1306_USE_DMA
CREATE_DISPLAY(128, 64, i2c1, 0x3C, 0, 0, main_display) ;
#endif

#define SLEEPTIME 25

void setup_gpios(void);
void animation(void);
Expand All @@ -40,48 +45,56 @@ void setup_gpios(void) {
gpio_pull_up(3);
}

void ssd1306_draw_string(ssd1306_t *disp, uint32_t x, uint32_t y, uint32_t scale, const char *s) {
ssd1306_draw_string_with_font(disp, x, y, scale, font_8x5, s);
}


void animation(void) {
const char *words[]= {"SSD1306", "DISPLAY", "DRIVER"};

ssd1306_t disp;
disp.external_vcc=false;
ssd1306_init(&disp, 128, 64, 0x3C, i2c1);
ssd1306_clear(&disp);
#ifdef SSD1306_USE_DMA
ssd1306_init(&main_display);
#else
ssd1306_t display_01;
display_01.external_vcc=false;
ssd1306_init(&display_01, 128, 64, 0x3C, i2c1);
#endif
ssd1306_clear(&main_display);

printf("ANIMATION!\n");

char buf[8];

for(;;) {
for(int y=0; y<31; ++y) {
ssd1306_draw_line(&disp, 0, y, 127, y);
ssd1306_show(&disp);
ssd1306_draw_line(&main_display, 0, y, 127, y);
ssd1306_show(&main_display);
sleep_ms(SLEEPTIME);
ssd1306_clear(&disp);
ssd1306_clear(&main_display);
}

for(int y=0, i=1; y>=0; y+=i) {
ssd1306_draw_line(&disp, 0, 31-y, 127, 31+y);
ssd1306_draw_line(&disp, 0, 31+y, 127, 31-y);
ssd1306_show(&disp);
ssd1306_draw_line(&main_display, 0, 31-y, 127, 31+y);
ssd1306_draw_line(&main_display, 0, 31+y, 127, 31-y);
ssd1306_show(&main_display);
sleep_ms(SLEEPTIME);
ssd1306_clear(&disp);
ssd1306_clear(&main_display);
if(y==32) i=-1;
}

for(int i=0; i<sizeof(words)/sizeof(char *); ++i) {
ssd1306_draw_string(&disp, 8, 24, 2, words[i]);
ssd1306_show(&disp);
ssd1306_draw_string(&main_display, 8, 24, 2, words[i]);
ssd1306_show(&main_display);
sleep_ms(800);
ssd1306_clear(&disp);
ssd1306_clear(&main_display);
}

for(int y=31; y<63; ++y) {
ssd1306_draw_line(&disp, 0, y, 127, y);
ssd1306_show(&disp);
ssd1306_draw_line(&main_display, 0, y, 127, y);
ssd1306_show(&main_display);
sleep_ms(SLEEPTIME);
ssd1306_clear(&disp);
ssd1306_clear(&main_display);
}

for(size_t font_i=0; font_i<sizeof(fonts)/sizeof(fonts[0]); ++font_i) {
Expand All @@ -95,15 +108,15 @@ void animation(void) {
}
buf[i]=0;

ssd1306_draw_string_with_font(&disp, 8, 24, 2, fonts[font_i], buf);
ssd1306_show(&disp);
ssd1306_draw_string_with_font(&main_display, 8, 24, 2, fonts[font_i], buf);
ssd1306_show(&main_display);
sleep_ms(800);
ssd1306_clear(&disp);
ssd1306_clear(&main_display);
}
}

ssd1306_bmp_show_image(&disp, image_data, image_size);
ssd1306_show(&disp);
ssd1306_bmp_show_image(&main_display, image_data, image_size);
ssd1306_show(&main_display);
sleep_ms(2000);
}
}
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions example/usb_cdc_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.13)

# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)

project(usb-cdc-example)

set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(USE_DMA_FOR_DISPLAY "Use the DMA engine to move the display buffer to the display" ON)

# initialize the Raspberry Pi Pico SDK
pico_sdk_init()

# add the subdirectory containing the ssd1306 library code
add_subdirectory(../../src lib)

# create the example target
add_executable(usb-cdc-example
usb_ssd1306.c
usb_cdc_descriptors.c
)

# make sure the example target sees the fonts
target_include_directories(usb-cdc-example
PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}/../../fonts
)

if(USE_DMA_FOR_DISPLAY)
message(STATUS "Using DMA")
target_compile_definitions(usb-cdc-example
PUBLIC
SSD1306_USE_DMA
)
target_link_libraries(usb-cdc-example
hardware_dma
)
endif(USE_DMA_FOR_DISPLAY)

target_link_libraries(usb-cdc-example
pico_stdlib
pico_unique_id
hardware_i2c
ssd1306
ssd1306_widgets
tinyusb_device
tinyusb_board
)

pico_enable_stdio_usb(usb-cdc-example 0)
pico_enable_stdio_uart(usb-cdc-example 1)
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(usb-cdc-example)
62 changes: 62 additions & 0 deletions example/usb_cdc_example/pico_sdk_import.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake

# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()

if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()

set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")

if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()

get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()

set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()

set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)

include(${PICO_SDK_INIT_CMAKE_FILE})
Loading