├── .gitignore ├── Basic_peripherals ├── SDcard_SPI │ └── README.md ├── sensor_acelerometro_giroscopio │ └── README.md ├── sensor_cor │ └── README.md ├── sensor_distancia_laser │ └── README.md ├── sensor_luz │ └── README.md ├── sensor_oximetro_bc │ └── README.md ├── sensor_temp_pressao │ └── README.md ├── sensor_temp_umidade │ └── README.md └── teclado_4x4 │ └── README.md ├── Joystick_led ├── CMakeLists.txt ├── diagram.json ├── joystick.c ├── pico-sdk.lnk ├── pico_sdk_import.cmake └── wokwi.toml ├── PWM+Display+Buzzer ├── .gitignore ├── BitDogLab.c ├── CMakeLists.txt ├── diagram.json ├── notes.h ├── pico_sdk_import.cmake ├── play_audio.c ├── play_audio.h ├── ssd1306.h ├── ssd1306_font.h ├── ssd1306_i2c.c ├── ssd1306_i2c.h └── wokwi.toml ├── PWM_LED_0 ├── .gitignore ├── CMakeLists.txt ├── PWM_LED_0.c └── pico_sdk_import.cmake ├── README.md ├── abordagem_hibrida ├── .gitignore ├── CMakeLists.txt ├── README.md ├── abordagem_hibrida.c └── pico_sdk_import.cmake ├── blink ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── blink.c ├── images │ └── blink-fluxograma.png └── pico_sdk_import.cmake ├── button-buzzer ├── .gitignore ├── CMakeLists.txt ├── button-buzzer.c └── pico_sdk_import.cmake ├── button ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── button.c ├── images │ ├── button-data_diagram.png │ └── button-fluxograma.jpg └── pico_sdk_import.cmake ├── button_led_rgb ├── .gitignore ├── CMakeLists.txt ├── button_led_rgb.c └── pico_sdk_import.cmake ├── buzzer ├── .gitignore ├── CMakeLists.txt ├── buzzer.c └── pico_sdk_import.cmake ├── buzzer_pwm1 ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── buzzer_pwm1.c ├── images │ ├── buzzer-diagrama.png │ ├── buzzer-fluxograma.png │ └── buzzer-imagem.png └── pico_sdk_import.cmake ├── codigo_modular ├── .gitignore ├── CMakeLists.txt ├── app │ └── codigo_modular.c ├── drivers │ └── led_embutido.c ├── hal │ └── hal_led.c ├── include │ ├── hal_led.h │ └── led_embutido.h └── pico_sdk_import.cmake ├── display_oled ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── display_oled.c ├── images │ └── bitmap_info.png ├── inc │ ├── ssd1306.h │ ├── ssd1306_font.h │ ├── ssd1306_i2c.c │ └── ssd1306_i2c.h └── pico_sdk_import.cmake ├── display_oled_logo ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── display_oled.c ├── images │ └── bitmap_info.png ├── inc │ ├── ssd1306.h │ ├── ssd1306_font.h │ ├── ssd1306_i2c.c │ └── ssd1306_i2c.h └── pico_sdk_import.cmake ├── goertzel ├── .gitignore ├── CMakeLists.txt ├── goertzel.c └── pico_sdk_import.cmake ├── iot_security_lab ├── .gitignore ├── CMakeLists.txt ├── include │ ├── mqtt_comm.h │ ├── wifi_conn.h │ └── xor_cipher.h ├── iot_security_lab.c ├── lwipopts.h ├── pico_sdk_import.cmake └── src │ ├── mqtt_comm.c │ ├── wifi_conn.c │ └── xor_cipher.c ├── isr_count_2btn ├── .gitignore ├── CMakeLists.txt ├── inc │ ├── ssd1306.h │ ├── ssd1306_font.h │ ├── ssd1306_i2c.c │ └── ssd1306_i2c.h ├── isr_count_2btn.c └── pico_sdk_import.cmake ├── joystick ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── images │ ├── joystick-esquema.png │ └── joystick-fluxograma.png ├── joystick.c └── pico_sdk_import.cmake ├── led_rgb ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── images │ ├── led_rgb-rgb.png │ └── led_rgb-rgb_variaveis.png ├── led_rgb.c └── pico_sdk_import.cmake ├── microphone_dma ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── images │ ├── microfone_circuito_esquema.png │ ├── microfone_circuito_foto.png │ └── microfone_fluxograma.png ├── microphone_dma.c ├── neopixel.c ├── pico_sdk_import.cmake └── ws2818b.pio ├── neopixel_pio ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── docs │ ├── neopixel_pio.drawio │ ├── neopixel_pio.drawio.png │ ├── neopixel_pio_sm.drawio │ └── neopixel_pio_sm.drawio.png ├── images │ ├── 2leds_connection.png │ ├── code_ws2818b.png │ ├── esquema_led_rgb.png │ ├── fluxograma.png │ ├── fluxograma_pio.png │ ├── led_exercicio.png │ ├── matriz_coord_2_2.png │ ├── matriz_leds_connection.png │ └── matriz_vazia.png ├── neopixel_pio.c ├── pico_sdk_import.cmake └── ws2818b.pio ├── picow_ble_temp_sensor ├── .gitignore ├── CMakeLists.txt ├── README.md ├── btstack_config.h ├── client.c ├── lwipopts.h ├── pico_sdk_import.cmake ├── server.c ├── server_common.c ├── server_common.h ├── server_with_wifi.c └── temp_sensor.gatt ├── rgb_pwm ├── .gitignore ├── CMakeLists.txt ├── pico_sdk_import.cmake └── rgb_pwm.c ├── rtos-examples ├── FreeRTOS_Functions_QuickReference.pdf ├── Queue │ ├── .gitignore │ ├── CMakeLists.txt │ ├── FreeRTOSConfig.h │ ├── Queue.c │ └── pico_sdk_import.cmake ├── README.txt ├── blink │ ├── .gitignore │ ├── CMakeLists.txt │ ├── FreeRTOSConfig.h │ ├── blink.c │ └── pico_sdk_import.cmake ├── multitasking │ ├── .gitignore │ ├── CMakeLists.txt │ ├── FreeRTOSConfig.h │ ├── multitasking.c │ └── pico_sdk_import.cmake ├── mutex │ ├── .gitignore │ ├── CMakeLists.txt │ ├── FreeRTOSConfig.h │ ├── mutex.c │ └── pico_sdk_import.cmake └── semaforo │ ├── .gitignore │ ├── CMakeLists.txt │ ├── FreeRTOSConfig.h │ ├── pico_sdk_import.cmake │ └── semaforo.c ├── ssd1306 ├── .gitignore ├── CMakeLists.txt ├── inc │ ├── ssd1306.c │ └── ssd1306.h ├── pico_sdk_import.cmake └── ssd1306.c ├── unit_test_temp ├── .gitignore ├── CMakeLists.txt ├── pico_sdk_import.cmake └── unit_test_temp.c ├── wifi_button_and_led ├── .gitignore ├── CMakeLists.txt ├── lwipopts.h ├── pico_sdk_import.cmake └── pico_w_wifi_complete_example.c └── wifi_led ├── .gitignore ├── CMakeLists.txt ├── Readme.md ├── images ├── fluxograma_wifi_led.png └── print_tela_wifi_http.png ├── lwipopts.h ├── pico_sdk_import.cmake └── pico_w_wifi_example.c /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .vscode/ -------------------------------------------------------------------------------- /Basic_peripherals/SDcard_SPI/README.md: -------------------------------------------------------------------------------- 1 | # Placa extensora SDcard SPI 2 | 3 | ## Arquivos de driver para o módulo extensor SDcard SPI 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_acelerometro_giroscopio/README.md: -------------------------------------------------------------------------------- 1 | # Sensor Acelerômetro e Giroscópio 2 | 3 | ## Arquivos de driver para o módulo sensor acelerômetro e giroscópio MPU6050 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_cor/README.md: -------------------------------------------------------------------------------- 1 | # Sensor de Cor 2 | 3 | ## Arquivos de driver para o módulo sensor de cor GY-33 TCS34725 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_distancia_laser/README.md: -------------------------------------------------------------------------------- 1 | # Sensor de Distância a Laser 2 | 3 | ## Arquivos de driver para o módulo sensor de distância a Laser VL53L0X 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_luz/README.md: -------------------------------------------------------------------------------- 1 | # Sensor de Luminosidade 2 | 3 | ## Arquivos de driver para o módulo sensor de luminosidade BH1750 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_oximetro_bc/README.md: -------------------------------------------------------------------------------- 1 | # Sensor Oxímetro e Batimentos Cardíacos 2 | 3 | ## Arquivos de driver para o módulo sensor oxímetro e batimentos cardíacos MAX30100 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_temp_pressao/README.md: -------------------------------------------------------------------------------- 1 | # Sensor de Temperatura e Pressão 2 | 3 | ## Arquivos de driver para o módulo sensor de temperatura e pressão BMP280 4 | -------------------------------------------------------------------------------- /Basic_peripherals/sensor_temp_umidade/README.md: -------------------------------------------------------------------------------- 1 | # Sensor de Temperatura e Umidade 2 | 3 | ## Arquivos de driver para o módulo sensor de temperatura e umidade AHT10 4 | -------------------------------------------------------------------------------- /Basic_peripherals/teclado_4x4/README.md: -------------------------------------------------------------------------------- 1 | # Teclado Matricial 4x4 2 | 3 | ## Arquivos de driver para o módulo teclado matricial 4x4 4 | -------------------------------------------------------------------------------- /Joystick_led/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_2_Rel1) 9 | set(picotoolVersion 2.0.0) 10 | include(${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | # ==================================================================================== 12 | cmake_minimum_required(VERSION 3.21) 13 | 14 | include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) 15 | 16 | project(pico-projects C CXX ASM) 17 | 18 | pico_sdk_init() 19 | 20 | add_executable(joystick 21 | joystick.c 22 | ) 23 | 24 | # Modify the below lines to enable/disable output over UART/USB 25 | pico_enable_stdio_uart(joystick 0) 26 | pico_enable_stdio_usb(joystick 1) 27 | 28 | target_link_libraries(joystick pico_stdlib hardware_adc hardware_pwm) 29 | 30 | pico_add_extra_outputs(joystick) 31 | 32 | 33 | -------------------------------------------------------------------------------- /Joystick_led/diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "Uri Shaked", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { 7 | "type": "wokwi-pi-pico", 8 | "id": "pico", 9 | "top": 6.45, 10 | "left": 109.2, 11 | "attrs": { "env": "arduino-community" } 12 | }, 13 | { "type": "wokwi-led", "id": "led1", "top": 3, "left": 0, "attrs": { "color": "red" } }, 14 | { "type": "wokwi-led", "id": "led2", "top": 48, "left": 0, "attrs": { "color": "yellow" } }, 15 | { 16 | "type": "wokwi-led", 17 | "id": "led3", 18 | "top": 102, 19 | "left": -15.4, 20 | "attrs": { "color": "green" } 21 | }, 22 | { "type": "wokwi-potentiometer", "id": "pot1", "top": 8.3, "left": 239.8, "attrs": {} }, 23 | { "type": "wokwi-potentiometer", "id": "pot2", "top": 104.3, "left": 239.8, "attrs": {} }, 24 | { 25 | "type": "wokwi-pushbutton", 26 | "id": "btn1", 27 | "top": 179, 28 | "left": 240, 29 | "attrs": { "color": "green" } 30 | } 31 | ], 32 | "connections": [ 33 | [ "pico:GND.1", "led1:C", "black", [] ], 34 | [ "pico:GND.2", "led2:C", "black", [] ], 35 | [ "pico:GND.3", "led3:C", "black", [] ], 36 | [ "$serialMonitor:RX", "pico:GP0", "", [] ], 37 | [ "led2:A", "pico:GP11", "green", [ "v0" ] ], 38 | [ "led1:A", "pico:GP12", "green", [ "v0" ] ], 39 | [ "led3:A", "pico:GP13", "green", [ "v0" ] ], 40 | [ "pot1:GND", "pico:GND.8", "black", [ "v-38.4", "h-86.4" ] ], 41 | [ "pot1:VCC", "pico:VSYS", "red", [ "v0" ] ], 42 | [ "pot1:SIG", "pico:GP26", "green", [ "v0" ] ], 43 | [ "pot2:GND", "pot1:GND", "black", [ "v0" ] ], 44 | [ "pot2:VCC", "pot1:VCC", "red", [ "v0" ] ], 45 | [ "pot2:SIG", "pico:GP27", "green", [ "v0" ] ], 46 | [ "pot2:GND", "btn1:1.l", "black", [ "v0" ] ], 47 | [ "btn1:2.l", "btn1:1.l", "green", [ "h0" ] ], 48 | [ "btn1:1.r", "pico:GP22", "green", [ "v0" ] ], 49 | [ "btn1:1.r", "btn1:2.r", "green", [ "v19.2", "h-9.4" ] ] 50 | ], 51 | "dependencies": {} 52 | } -------------------------------------------------------------------------------- /Joystick_led/pico-sdk.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/Joystick_led/pico-sdk.lnk -------------------------------------------------------------------------------- /Joystick_led/wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | firmware ='./build/joystick.hex' 4 | elf = './build/joystick.elf' 5 | gdbServerPort=3333 -------------------------------------------------------------------------------- /PWM+Display+Buzzer/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /PWM+Display+Buzzer/BitDogLab.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "pico/stdlib.h" 6 | #include "pico/binary_info.h" 7 | #include "ssd1306.h" 8 | #include "hardware/i2c.h" 9 | #include "play_audio.h" 10 | 11 | const uint I2C_SDA_PIN = 14; 12 | const uint I2C_SCL_PIN = 15; 13 | 14 | int main() 15 | { 16 | stdio_init_all(); 17 | setup_audio(); 18 | 19 | // I2C is "open drain", pull ups to keep signal high when no data is being 20 | // sent 21 | i2c_init(i2c1, SSD1306_I2C_CLK * 1000); 22 | gpio_set_function(I2C_SDA_PIN, GPIO_FUNC_I2C); 23 | gpio_set_function(I2C_SCL_PIN, GPIO_FUNC_I2C); 24 | gpio_pull_up(I2C_SDA_PIN); 25 | gpio_pull_up(I2C_SCL_PIN); 26 | 27 | // run through the complete initialization process 28 | SSD1306_init(); 29 | 30 | // Initialize render area for entire frame (SSD1306_WIDTH pixels by SSD1306_NUM_PAGES pages) 31 | struct render_area frame_area = { 32 | start_col : 0, 33 | end_col : SSD1306_WIDTH - 1, 34 | start_page : 0, 35 | end_page : SSD1306_NUM_PAGES - 1 36 | }; 37 | 38 | calc_render_area_buflen(&frame_area); 39 | 40 | // zero the entire display 41 | uint8_t buf[SSD1306_BUF_LEN]; 42 | memset(buf, 0, SSD1306_BUF_LEN); 43 | render(buf, &frame_area); 44 | 45 | restart: 46 | 47 | SSD1306_scroll(true); 48 | sleep_ms(5000); 49 | SSD1306_scroll(false); 50 | 51 | char *text[] = { 52 | " Bem-Vindo ", 53 | " ao EmbarcaTech ", 54 | " 2024 ", 55 | " SOFTEX/MCTI "}; 56 | 57 | int y = 0; 58 | for (uint i = 0; i < count_of(text); i++) 59 | { 60 | WriteString(buf, 5, y, text[i]); 61 | y += 8; 62 | } 63 | render(buf, &frame_area); 64 | 65 | while (true){ 66 | main_audio(); 67 | } 68 | 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /PWM+Display+Buzzer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(BitDogLab C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(BitDogLab BitDogLab.c ssd1306_i2c.c play_audio.c) 39 | 40 | pico_set_program_name(BitDogLab "BitDogLab") 41 | pico_set_program_version(BitDogLab "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(BitDogLab 0) 45 | pico_enable_stdio_usb(BitDogLab 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(BitDogLab 49 | pico_stdlib hardware_i2c hardware_pwm) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(BitDogLab PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required 55 | ) 56 | 57 | pico_add_extra_outputs(BitDogLab) 58 | 59 | -------------------------------------------------------------------------------- /PWM+Display+Buzzer/diagram.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "author": "Uri Shaked", 4 | "editor": "wokwi", 5 | "parts": [ 6 | { 7 | "type": "wokwi-pi-pico", 8 | "id": "pico", 9 | "top": 20, 10 | "left": 60, 11 | "attrs": { "env": "arduino-community" } 12 | }, 13 | { "type": "wokwi-led", "id": "led1", "top": 3, "left": 0, "attrs": { "color": "red" } }, 14 | { "type": "wokwi-led", "id": "led2", "top": 48, "left": 0, "attrs": { "color": "yellow" } }, 15 | { "type": "wokwi-led", "id": "led3", "top": 98, "left": 0, "attrs": { "color": "green" } }, 16 | { 17 | "type": "board-ssd1306", 18 | "id": "oled1", 19 | "top": 185.54, 20 | "left": -124.57, 21 | "attrs": { "i2cAddress": "0x3c" } 22 | } 23 | ], 24 | "connections": [ 25 | [ "pico:GND.1", "led1:C", "black", [] ], 26 | [ "pico:GP1", "led1:A", "blue", [] ], 27 | [ "pico:GND.2", "led2:C", "black", [] ], 28 | [ "pico:GP5", "led2:A", "blue", [] ], 29 | [ "pico:GND.3", "led3:C", "black", [] ], 30 | [ "pico:GP9", "led3:A", "blue", [] ], 31 | [ "$serialMonitor:RX", "pico:GP0", "", [] ], 32 | [ "oled1:SDA", "pico:GP14", "green", [ "v0" ] ], 33 | [ "pico:GP15", "oled1:SCL", "green", [ "h-75.6", "v-51.95", "h-57.6" ] ], 34 | [ "oled1:VCC", "pico:3V3_EN", "red", [ "v0" ] ], 35 | [ "oled1:GND", "pico:GND.4", "black", [ "v0" ] ] 36 | ], 37 | "dependencies": {} 38 | } -------------------------------------------------------------------------------- /PWM+Display+Buzzer/notes.h: -------------------------------------------------------------------------------- 1 | #define NOTE_C4 29886 2 | #define NOTE_Cs4 28294 3 | #define NOTE_C5 14929 4 | #define NOTE_C6 7465 5 | #define NOTE_D4 26795 6 | #define NOTE_D5 13298 7 | #define NOTE_DS4 25386 8 | #define NOTE_E4 24063 9 | #define NOTE_F4 22823 10 | #define NOTE_FS5 9561 11 | #define NOTE_Fs4 21663 12 | #define NOTE_G4 20579 13 | #define NOTE_G5 8966 14 | #define NOTE_GS5 9409 15 | #define NOTE_GS4 19569 16 | #define NOTE_A4 18630 17 | #define NOTE_AS4 177758 18 | #define NOTE_AS5 8380 19 | #define NOTE_AS3 33498 20 | #define NOTE_B4 16952 21 | 22 | #define SONG_B_LENGTH 129 23 | 24 | int melody[] = { 25 | NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, 26 | NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, 27 | NOTE_G4, NOTE_C4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_E4, NOTE_F4, 28 | NOTE_G4, NOTE_C4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_E4, NOTE_F4, 29 | NOTE_G4, NOTE_C4, 30 | 31 | NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, 32 | NOTE_D4, 33 | NOTE_F4, NOTE_AS3, 34 | NOTE_DS4, NOTE_D4, NOTE_F4, NOTE_AS3, 35 | NOTE_DS4, NOTE_D4, NOTE_C4, 36 | 37 | NOTE_G4, NOTE_C4, 38 | 39 | NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, 40 | NOTE_D4, 41 | NOTE_F4, NOTE_AS3, 42 | NOTE_DS4, NOTE_D4, NOTE_F4, NOTE_AS3, 43 | NOTE_DS4, NOTE_D4, NOTE_C4, 44 | NOTE_G4, NOTE_C4, 45 | NOTE_DS4, NOTE_F4, NOTE_G4, NOTE_C4, NOTE_DS4, NOTE_F4, 46 | 47 | NOTE_D4, 48 | NOTE_F4, NOTE_AS3, 49 | NOTE_D4, NOTE_DS4, NOTE_D4, NOTE_AS3, 50 | NOTE_C4, 51 | NOTE_C5, 52 | NOTE_AS4, 53 | NOTE_C4, 54 | NOTE_G4, 55 | NOTE_DS4, 56 | NOTE_DS4, NOTE_F4, 57 | NOTE_G4, 58 | 59 | NOTE_C5, 60 | NOTE_AS4, 61 | NOTE_C4, 62 | NOTE_G4, 63 | NOTE_DS4, 64 | NOTE_DS4, NOTE_D4, 65 | NOTE_C5, NOTE_G4, NOTE_GS4, NOTE_AS4, NOTE_C5, NOTE_G4, NOTE_GS4, NOTE_AS4, 66 | NOTE_C5, NOTE_G4, NOTE_GS4, NOTE_AS4, NOTE_C5, NOTE_G4, NOTE_GS4, NOTE_AS4, 67 | 68 | NOTE_GS5, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_GS5, NOTE_AS5, 69 | NOTE_C6, NOTE_G5, NOTE_GS5, NOTE_AS5, NOTE_C6, NOTE_G5, NOTE_GS5, NOTE_AS5}; 70 | 71 | int durations[] = { 72 | 8, 8, 16, 16, 8, 8, 16, 16, 73 | 8, 8, 16, 16, 8, 8, 16, 16, 74 | 8, 8, 16, 16, 8, 8, 16, 16, 75 | 8, 8, 16, 16, 8, 8, 16, 16, 76 | 4, 4, 77 | 78 | 16, 16, 4, 4, 16, 16, 79 | 1, 80 | 4, 4, 81 | 16, 16, 4, 4, 82 | 16, 16, 1, 83 | 84 | 4, 4, 85 | 86 | 16, 16, 4, 4, 16, 16, 87 | 1, 88 | 4, 4, 89 | 16, 16, 4, 4, 90 | 16, 16, 1, 91 | 4, 4, 92 | 16, 16, 4, 4, 16, 16, 93 | 94 | 2, 95 | 4, 4, 96 | 8, 8, 8, 8, 97 | 1, 98 | 2, 99 | 2, 100 | 2, 101 | 2, 102 | 2, 103 | 4, 4, 104 | 1, 105 | 106 | 2, 107 | 2, 108 | 2, 109 | 2, 110 | 2, 111 | 4, 4, 112 | 8, 8, 16, 16, 8, 8, 16, 16, 113 | 8, 8, 16, 16, 8, 8, 16, 16, 114 | 115 | 16, 16, 8, 8, 16, 16, 116 | 8, 16, 16, 16, 8, 8, 16, 16}; 117 | -------------------------------------------------------------------------------- /PWM+Display+Buzzer/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /PWM+Display+Buzzer/play_audio.h: -------------------------------------------------------------------------------- 1 | extern int main_audio(); 2 | extern void setup_audio(); -------------------------------------------------------------------------------- /PWM+Display+Buzzer/ssd1306.h: -------------------------------------------------------------------------------- 1 | #include "ssd1306_i2c.h" 2 | extern void calc_render_area_buflen(struct render_area *area); 3 | extern void SSD1306_send_cmd(uint8_t cmd); 4 | extern void SSD1306_send_cmd_list(uint8_t *buf, int num); 5 | extern void SSD1306_send_buf(uint8_t buf[], int buflen); 6 | extern void SSD1306_init(); 7 | extern void SSD1306_scroll(bool on); 8 | extern void render(uint8_t *buf, struct render_area *area); 9 | extern void SetPixel(uint8_t *buf, int x, int y, bool on); 10 | extern void DrawLine(uint8_t *buf, int x0, int y0, int x1, int y1, bool on); 11 | extern void WriteChar(uint8_t *buf, int16_t x, int16_t y, uint8_t ch); 12 | extern void WriteString(uint8_t *buf, int16_t x, int16_t y, char *str); -------------------------------------------------------------------------------- /PWM+Display+Buzzer/ssd1306_font.h: -------------------------------------------------------------------------------- 1 | 2 | static uint8_t font[] = { 3 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Nothing 4 | 0x78, 0x14, 0x12, 0x11, 0x12, 0x14, 0x78, 0x00, // A 5 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x7f, 0x00, // B 6 | 0x7e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, // C 7 | 0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x7e, 0x00, // D 8 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, // E 9 | 0x7f, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x00, // F 10 | 0x7f, 0x41, 0x41, 0x41, 0x51, 0x51, 0x73, 0x00, // G 11 | 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7f, 0x00, // H 12 | 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, // I 13 | 0x21, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x01, 0x00, // J 14 | 0x00, 0x7f, 0x08, 0x08, 0x14, 0x22, 0x41, 0x00, // K 15 | 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, // L 16 | 0x7f, 0x02, 0x04, 0x08, 0x04, 0x02, 0x7f, 0x00, // M 17 | 0x7f, 0x02, 0x04, 0x08, 0x10, 0x20, 0x7f, 0x00, // N 18 | 0x3e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, 0x00, // O 19 | 0x7f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00, // P 20 | 0x3e, 0x41, 0x41, 0x49, 0x51, 0x61, 0x7e, 0x00, // Q 21 | 0x7f, 0x11, 0x11, 0x11, 0x31, 0x51, 0x0e, 0x00, // R 22 | 0x46, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // S 23 | 0x01, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x01, 0x00, // T 24 | 0x3f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x3f, 0x00, // U 25 | 0x0f, 0x10, 0x20, 0x40, 0x20, 0x10, 0x0f, 0x00, // V 26 | 0x7f, 0x20, 0x10, 0x08, 0x10, 0x20, 0x7f, 0x00, // W 27 | 0x00, 0x41, 0x22, 0x14, 0x14, 0x22, 0x41, 0x00, // X 28 | 0x01, 0x02, 0x04, 0x78, 0x04, 0x02, 0x01, 0x00, // Y 29 | 0x41, 0x61, 0x59, 0x45, 0x43, 0x41, 0x00, 0x00, // Z 30 | 0x3e, 0x41, 0x41, 0x49, 0x41, 0x41, 0x3e, 0x00, // 0 31 | 0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x00, // 1 32 | 0x30, 0x49, 0x49, 0x49, 0x49, 0x46, 0x00, 0x00, // 2 33 | 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 3 34 | 0x3f, 0x20, 0x20, 0x78, 0x20, 0x20, 0x00, 0x00, // 4 35 | 0x4f, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // 5 36 | 0x3f, 0x48, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, // 6 37 | 0x01, 0x01, 0x01, 0x61, 0x31, 0x0d, 0x03, 0x00, // 7 38 | 0x36, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 8 39 | 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x7f, 0x00, // 9 40 | }; -------------------------------------------------------------------------------- /PWM+Display+Buzzer/ssd1306_i2c.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | SSD1306 I2C Library for Raspberry Pi. 3 | Based on Adafruit SSD1306 Arduino library. Some functions came from Adafruit GFX lib. 4 | 5 | Modified by Ilia Penev 6 | Tested on Raspberry Pi 2 with 0.96 Yellow/Blue OLED 7 | *********************************************************************/ 8 | 9 | /********************************************************************* 10 | This is a library for our Monochrome OLEDs based on SSD1306 drivers 11 | 12 | Pick one up today in the adafruit shop! 13 | ------> http://www.adafruit.com/category/63_98 14 | 15 | These displays use SPI to communicate, 4 or 5 pins are required to 16 | interface 17 | 18 | Adafruit invests time and resources providing this open source code, 19 | please support Adafruit and open-source hardware by purchasing 20 | products from Adafruit! 21 | 22 | Written by Limor Fried/Ladyada for Adafruit Industries. 23 | BSD license, check license.txt for more information 24 | All text above, and the splash screen must be included in any redistribution 25 | *********************************************************************/ 26 | #ifndef SSD1306_I2C_H_ 27 | #define SSD1306_I2C_H_ 28 | 29 | // Define the size of the display we have attached. This can vary, make sure you 30 | // have the right size defined or the output will look rather odd! 31 | // Code has been tested on 128x32 and 128x64 OLED displays 32 | #define SSD1306_HEIGHT 32 33 | #define SSD1306_WIDTH 128 34 | 35 | #define SSD1306_I2C_ADDR _u(0x3C) 36 | 37 | // 400 is usual, but often these can be overclocked to improve display response. 38 | // Tested at 1000 on both 32 and 84 pixel height devices and it worked. 39 | #define SSD1306_I2C_CLK 400 40 | // #define SSD1306_I2C_CLK 1000 41 | 42 | // commands (see datasheet) 43 | #define SSD1306_SET_MEM_MODE _u(0x20) 44 | #define SSD1306_SET_COL_ADDR _u(0x21) 45 | #define SSD1306_SET_PAGE_ADDR _u(0x22) 46 | #define SSD1306_SET_HORIZ_SCROLL _u(0x26) 47 | #define SSD1306_SET_SCROLL _u(0x2E) 48 | 49 | #define SSD1306_SET_DISP_START_LINE _u(0x40) 50 | 51 | #define SSD1306_SET_CONTRAST _u(0x81) 52 | #define SSD1306_SET_CHARGE_PUMP _u(0x8D) 53 | 54 | #define SSD1306_SET_SEG_REMAP _u(0xA0) 55 | #define SSD1306_SET_ENTIRE_ON _u(0xA4) 56 | #define SSD1306_SET_ALL_ON _u(0xA5) 57 | #define SSD1306_SET_NORM_DISP _u(0xA6) 58 | #define SSD1306_SET_INV_DISP _u(0xA7) 59 | #define SSD1306_SET_MUX_RATIO _u(0xA8) 60 | #define SSD1306_SET_DISP _u(0xAE) 61 | #define SSD1306_SET_COM_OUT_DIR _u(0xC0) 62 | #define SSD1306_SET_COM_OUT_DIR_FLIP _u(0xC0) 63 | 64 | #define SSD1306_SET_DISP_OFFSET _u(0xD3) 65 | #define SSD1306_SET_DISP_CLK_DIV _u(0xD5) 66 | #define SSD1306_SET_PRECHARGE _u(0xD9) 67 | #define SSD1306_SET_COM_PIN_CFG _u(0xDA) 68 | #define SSD1306_SET_VCOM_DESEL _u(0xDB) 69 | 70 | #define SSD1306_PAGE_HEIGHT _u(8) 71 | #define SSD1306_NUM_PAGES (SSD1306_HEIGHT / SSD1306_PAGE_HEIGHT) 72 | #define SSD1306_BUF_LEN (SSD1306_NUM_PAGES * SSD1306_WIDTH) 73 | 74 | #define SSD1306_WRITE_MODE _u(0xFE) 75 | #define SSD1306_READ_MODE _u(0xFF) 76 | 77 | struct render_area 78 | { 79 | uint8_t start_col; 80 | uint8_t end_col; 81 | uint8_t start_page; 82 | uint8_t end_page; 83 | 84 | int buflen; 85 | }; 86 | 87 | #endif /* _SSD1306_I2C_H_ */ -------------------------------------------------------------------------------- /PWM+Display+Buzzer/wokwi.toml: -------------------------------------------------------------------------------- 1 | [wokwi] 2 | version = 1 3 | firmware ='./build/BitDogLab.hex' 4 | elf = './build/BitDogLab.elf' 5 | gdbServerPort=3333 -------------------------------------------------------------------------------- /PWM_LED_0/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /PWM_LED_0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NEVER EDIT THE NEXT LINES for Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 2.0.0) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(PWM_LED_0 C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(PWM_LED_0 PWM_LED_0.c ) 39 | 40 | pico_set_program_name(PWM_LED_0 "PWM_LED_0") 41 | pico_set_program_version(PWM_LED_0 "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(PWM_LED_0 1) 45 | pico_enable_stdio_usb(PWM_LED_0 0) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(PWM_LED_0 49 | pico_stdlib hardware_pwm) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(PWM_LED_0 PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts or any other standard includes, if required 55 | ) 56 | 57 | pico_add_extra_outputs(PWM_LED_0) 58 | 59 | -------------------------------------------------------------------------------- /PWM_LED_0/PWM_LED_0.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/pwm.h" 4 | 5 | const uint LED = 12; // Pino do LED conectado 6 | const uint16_t PERIOD = 2000; // Período do PWM (valor máximo do contador) 7 | const float DIVIDER_PWM = 16.0; // Divisor fracional do clock para o PWM 8 | const uint16_t LED_STEP = 100; // Passo de incremento/decremento para o duty cycle do LED 9 | uint16_t led_level = 100; // Nível inicial do PWM (duty cycle) 10 | 11 | void setup_pwm() 12 | { 13 | uint slice; 14 | gpio_set_function(LED, GPIO_FUNC_PWM); // Configura o pino do LED para função PWM 15 | slice = pwm_gpio_to_slice_num(LED); // Obtém o slice do PWM associado ao pino do LED 16 | pwm_set_clkdiv(slice, DIVIDER_PWM); // Define o divisor de clock do PWM 17 | pwm_set_wrap(slice, PERIOD); // Configura o valor máximo do contador (período do PWM) 18 | pwm_set_gpio_level(LED, led_level); // Define o nível inicial do PWM para o pino do LED 19 | pwm_set_enabled(slice, true); // Habilita o PWM no slice correspondente 20 | } 21 | 22 | int main() 23 | { 24 | uint up_down = 1; // Variável para controlar se o nível do LED aumenta ou diminui 25 | stdio_init_all(); // Inicializa o sistema padrão de I/O 26 | setup_pwm(); // Configura o PWM 27 | while (true) 28 | { 29 | pwm_set_gpio_level(LED, led_level); // Define o nível atual do PWM (duty cycle) 30 | sleep_ms(1000); // Atraso de 1 segundo 31 | if (up_down) 32 | { 33 | led_level += LED_STEP; // Incrementa o nível do LED 34 | if (led_level >= PERIOD) 35 | up_down = 0; // Muda direção para diminuir quando atingir o período máximo 36 | } 37 | else 38 | { 39 | led_level -= LED_STEP; // Decrementa o nível do LED 40 | if (led_level <= LED_STEP) 41 | up_down = 1; // Muda direção para aumentar quando atingir o mínimo 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BitDogLab em C 2 | 3 | Este repositório contém diversos projetos para o controle dos componentes da BitDogLab na linguagem C, usando a Pico SDK. 4 | -------------------------------------------------------------------------------- /abordagem_hibrida/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /abordagem_hibrida/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 2.1.1) 19 | set(toolchainVersion 14_2_Rel1) 20 | set(picotoolVersion 2.1.1) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(abordagem_hibrida C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Adicione diretórios de includes locais 37 | include_directories( 38 | ${CMAKE_CURRENT_LIST_DIR}/include 39 | ${CMAKE_CURRENT_LIST_DIR}/lib/ssd1306 40 | ${CMAKE_CURRENT_LIST_DIR}/lib/usb_comm 41 | ) 42 | 43 | # Adicione diretórios de subprojetos 44 | add_subdirectory(lib/FreeRTOS-Kernel) # FreeRTOS clonado como subdiretório 45 | 46 | # Add executable. Default name is the project name, version 0.1 47 | add_executable(abordagem_hibrida abordagem_hibrida.c 48 | lib/ssd1306/ssd1306.c 49 | lib/usb_comm/usb_comm.c 50 | ) 51 | 52 | pico_set_program_name(abordagem_hibrida "abordagem_hibrida") 53 | pico_set_program_version(abordagem_hibrida "0.1") 54 | 55 | # Modify the below lines to enable/disable output over UART/USB 56 | pico_enable_stdio_uart(abordagem_hibrida 0) 57 | pico_enable_stdio_usb(abordagem_hibrida 1) 58 | 59 | # Add the standard library to the build 60 | target_link_libraries(abordagem_hibrida 61 | pico_stdlib 62 | hardware_gpio 63 | hardware_irq 64 | FreeRTOS-Kernel 65 | ) 66 | 67 | # Add the standard include files to the build 68 | target_include_directories(abordagem_hibrida PRIVATE 69 | ${CMAKE_CURRENT_LIST_DIR} 70 | ) 71 | 72 | # Add any user requested libraries 73 | target_link_libraries(abordagem_hibrida 74 | 75 | ) 76 | 77 | pico_add_extra_outputs(abordagem_hibrida) 78 | 79 | -------------------------------------------------------------------------------- /abordagem_hibrida/README.md: -------------------------------------------------------------------------------- 1 | ### 📜 Exemplo: Botão com Interrupção, LED RGB, e Tarefa de RTOS (BitDogLab) 2 | 3 | **Exemplo prático na BitDogLab:** 4 | - Uma interrupção de botão (GPIO) sinaliza um evento com uma flag. 5 | - O loop principal (executor cíclico) verifica essa flag e acende o LED RGB. 6 | - Uma tarefa do RTOS cuida da atualização do display OLED e comunicação USB. 7 | 8 | --- 9 | 10 | **Estrutura geral:** 11 | - Interrupção de GPIO: Aciona uma flag global. 12 | - Loop principal: Verifica a flag e acende o LED RGB. 13 | - Tarefa RTOS: Atualiza o display OLED e gerencia comunicação USB. 14 | 15 | --- 16 | 17 | **🛠️ Resumo Técnico** 18 | | Elemento | Descrição | 19 | |----------------|---------------------------------------------------------------------| 20 | | Button ISR | Captura borda de descida e seta a flag. | 21 | | Loop (Idle Hook)| Verifica a flag e controla o LED RGB. | 22 | | Tarefa RTOS | Atualiza o display OLED e envia status via USB. | 23 | | Uso de FreeRTOS| Separação clara entre eventos assíncronos e tarefas de serviço. | 24 | 25 | --- 26 | 27 | **📌 Observações práticas:** 28 | - gpio_set_irq_enabled_with_callback já cuida de registrar seu handler de interrupção. 29 | - A flag precisa ser volatile para sincronização entre ISR e o loop principal. 30 | - O Idle Hook (vApplicationIdleHook) é ótimo para um "executor cíclico" leve se você não quiser criar outra tarefa RTOS para verificar flags. 31 | 32 | --- 33 | 34 | **📂 Estrutura esperada de pastas:** 35 | 36 | abordagem_hibrida/ 37 | ├── CMakeLists.txt 38 | ├── main.c 39 | ├── include/ 40 | │ ├── ssd1306.h 41 | │ └── usb_comm.h 42 | ├── lib/ 43 | │ ├── ssd1306/ 44 | │ │ ├── ssd1306.c 45 | │ │ └── ssd1306.h 46 | │ ├── usb_comm/ 47 | │ │ ├── usb_comm.c 48 | │ │ └── usb_comm.h 49 | │ └── FreeRTOS-Kernel/ 50 | │ ├── CMakeLists.txt 51 | │ └── (resto do FreeRTOS) 52 | └── build/ 53 | └── (onde será gerado) 54 | 55 | --- 56 | 57 | **⚡ Notas Rápidas** 58 | - FreeRTOS-Kernel: você precisa clonar ou copiar o kernel do FreeRTOS para dentro de lib/FreeRTOS-Kernel/ e colocar um CMakeLists.txt lá também. 59 | - ssd1306.c e usb_comm.c são bibliotecas básicas que precisam implementar inicialização e operação do display e da USB. 60 | - hardware_gpio e hardware_irq são módulos específicos da Pico SDK que lidam com GPIOs e interrupções. 61 | 62 | -------------------------------------------------------------------------------- /abordagem_hibrida/abordagem_hibrida.c: -------------------------------------------------------------------------------- 1 | // Exemplo prático (em construção) na BitDogLab: 2 | // - Uma interrupção de botão (GPIO) sinaliza um evento com uma flag. 3 | // - O loop principal (executor cíclico) verifica essa flag e acende o LED RGB. 4 | // - Uma tarefa do RTOS cuida da atualização do display OLED e comunicação USB. 5 | 6 | #include "pico/stdlib.h" 7 | #include "hardware/gpio.h" 8 | #include "hardware/irq.h" 9 | #include "FreeRTOS.h" 10 | #include "task.h" 11 | #include "ssd1306.h" // Supomos uma lib para display OLED SSD1306 12 | #include "usb_comm.h" // Supomos lib para comunicação USB 13 | 14 | #define BUTTON_PIN 15 15 | #define LED_R_PIN 16 16 | #define LED_G_PIN 17 17 | #define LED_B_PIN 18 18 | 19 | volatile bool button_pressed_flag = false; // Flag global, modificada pela interrupção 20 | 21 | // Interrupção do botão 22 | void button_isr(uint gpio, uint32_t events) { 23 | if (gpio == BUTTON_PIN && (events & GPIO_IRQ_EDGE_FALL)) { 24 | button_pressed_flag = true; 25 | } 26 | } 27 | 28 | // Tarefa do RTOS para Display OLED + USB 29 | void vTask_DisplayAndUSB(void *pvParameters) { 30 | ssd1306_init(); // Inicializa o display OLED 31 | usb_comm_init(); // Inicializa a comunicação USB 32 | 33 | while (1) { 34 | ssd1306_clear(); 35 | ssd1306_draw_string(0, 0, "BitDogLab: Rodando"); 36 | ssd1306_update(); 37 | 38 | usb_comm_send("Status: OK\n"); 39 | 40 | vTaskDelay(pdMS_TO_TICKS(1000)); // Atualiza a cada 1 segundo 41 | } 42 | } 43 | 44 | // Inicializa LEDs 45 | void init_leds(void) { 46 | gpio_init(LED_R_PIN); 47 | gpio_set_dir(LED_R_PIN, GPIO_OUT); 48 | gpio_init(LED_G_PIN); 49 | gpio_set_dir(LED_G_PIN, GPIO_OUT); 50 | gpio_init(LED_B_PIN); 51 | gpio_set_dir(LED_B_PIN, GPIO_OUT); 52 | } 53 | 54 | // Inicializa botão com interrupção 55 | void init_button(void) { 56 | gpio_init(BUTTON_PIN); 57 | gpio_set_dir(BUTTON_PIN, GPIO_IN); 58 | gpio_pull_up(BUTTON_PIN); 59 | gpio_set_irq_enabled_with_callback(BUTTON_PIN, GPIO_IRQ_EDGE_FALL, true, &button_isr); 60 | } 61 | 62 | int main() { 63 | stdio_init_all(); 64 | init_leds(); 65 | init_button(); 66 | 67 | // Cria a tarefa de Display e USB 68 | xTaskCreate(vTask_DisplayAndUSB, "Display_USB", 1024, NULL, 1, NULL); 69 | 70 | // Start scheduler 71 | vTaskStartScheduler(); 72 | 73 | while (true) { 74 | // Nunca deve chegar aqui com RTOS rodando 75 | } 76 | } 77 | 78 | // Hook para loop ocioso, opcionalmente usado se quiser um "executor cíclico" 79 | void vApplicationIdleHook(void) { 80 | // Loop principal: verifica flag e acende LED 81 | if (button_pressed_flag) { 82 | gpio_put(LED_R_PIN, 1); 83 | gpio_put(LED_G_PIN, 0); 84 | gpio_put(LED_B_PIN, 0); 85 | 86 | // Reseta a flag 87 | button_pressed_flag = false; 88 | } else { 89 | // LED apagado 90 | gpio_put(LED_R_PIN, 0); 91 | gpio_put(LED_G_PIN, 0); 92 | gpio_put(LED_B_PIN, 0); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /blink/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(blink C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(blink blink.c ) 39 | 40 | pico_set_program_name(blink "blink") 41 | pico_set_program_version(blink "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(blink 0) 45 | pico_enable_stdio_usb(blink 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(blink 49 | pico_stdlib) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(blink PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | pico_add_extra_outputs(blink) 57 | 58 | -------------------------------------------------------------------------------- /blink/blink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/gpio.h" 4 | 5 | #define LEDR 12 6 | #define LEDG 11 7 | #define LEDB 13 8 | 9 | void led_rgb_put(bool r, bool g, bool b) { 10 | gpio_put(LEDR, r); 11 | gpio_put(LEDG, g); 12 | gpio_put(LEDB, b); 13 | } 14 | 15 | int main() { 16 | stdio_init_all(); 17 | 18 | gpio_init(LEDR); 19 | gpio_init(LEDG); 20 | gpio_init(LEDB); 21 | 22 | gpio_set_slew_rate(LEDR, GPIO_SLEW_RATE_SLOW); 23 | gpio_set_slew_rate(LEDG, GPIO_SLEW_RATE_SLOW); 24 | gpio_set_slew_rate(LEDB, GPIO_SLEW_RATE_SLOW); 25 | 26 | gpio_set_dir(LEDR, true); 27 | gpio_set_dir(LEDG, true); 28 | gpio_set_dir(LEDB, true); 29 | 30 | while (true) { 31 | led_rgb_put(true, false, false); 32 | sleep_ms(500); 33 | led_rgb_put(false, true, false); 34 | sleep_ms(500); 35 | led_rgb_put(false, false, true); 36 | sleep_ms(500); 37 | led_rgb_put(true, true, true); 38 | sleep_ms(500); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /blink/images/blink-fluxograma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/blink/images/blink-fluxograma.png -------------------------------------------------------------------------------- /button-buzzer/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /button-buzzer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.1.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(button-buzzer C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(button-buzzer button-buzzer.c ) 39 | 40 | pico_set_program_name(button-buzzer "button-buzzer") 41 | pico_set_program_version(button-buzzer "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(button-buzzer 0) 45 | pico_enable_stdio_usb(button-buzzer 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(button-buzzer 49 | pico_stdlib 50 | hardware_pwm) 51 | 52 | # Add the standard include files to the build 53 | target_include_directories(button-buzzer PRIVATE 54 | ${CMAKE_CURRENT_LIST_DIR} 55 | ) 56 | 57 | # Add any user requested libraries 58 | target_link_libraries(button-buzzer 59 | 60 | ) 61 | 62 | pico_add_extra_outputs(button-buzzer) 63 | 64 | -------------------------------------------------------------------------------- /button-buzzer/button-buzzer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | 4 | #include "hardware/pwm.h" 5 | #include "hardware/clocks.h" 6 | 7 | // Configuração do pino do buzzer 8 | #define BUZZER_PIN 21 9 | 10 | // Configuração da frequência do buzzer (em Hz) 11 | #define BUZZER_FREQUENCY 100 12 | 13 | // Definição de uma função para inicializar o PWM no pino do buzzer 14 | void pwm_init_buzzer(uint pin) { 15 | // Configurar o pino como saída de PWM 16 | gpio_set_function(pin, GPIO_FUNC_PWM); 17 | 18 | // Obter o slice do PWM associado ao pino 19 | uint slice_num = pwm_gpio_to_slice_num(pin); 20 | 21 | // Configurar o PWM com frequência desejada 22 | pwm_config config = pwm_get_default_config(); 23 | pwm_config_set_clkdiv(&config, clock_get_hz(clk_sys) / (BUZZER_FREQUENCY * 4096)); // Divisor de clock 24 | pwm_init(slice_num, &config, true); 25 | 26 | // Iniciar o PWM no nível baixo 27 | pwm_set_gpio_level(pin, 0); 28 | } 29 | 30 | // Definição de uma função para emitir um beep com duração especificada 31 | void beep(uint pin, uint duration_ms) { 32 | // Obter o slice do PWM associado ao pino 33 | uint slice_num = pwm_gpio_to_slice_num(pin); 34 | 35 | // Configurar o duty cycle para 50% (ativo) 36 | pwm_set_gpio_level(pin, 2048); 37 | 38 | // Temporização 39 | sleep_ms(duration_ms); 40 | 41 | // Desativar o sinal PWM (duty cycle 0) 42 | pwm_set_gpio_level(pin, 0); 43 | 44 | // Pausa entre os beeps 45 | sleep_ms(100); // Pausa de 100ms 46 | } 47 | 48 | int main() { 49 | // Configuração do GPIO para o botão como entrada com pull-up 50 | const uint BUTTON_PIN = 5; // Pino do botão 51 | gpio_init(BUTTON_PIN); 52 | gpio_set_dir(BUTTON_PIN, GPIO_IN); 53 | gpio_pull_up(BUTTON_PIN); 54 | 55 | // Configuração do GPIO para o buzzer como saída 56 | gpio_init(BUZZER_PIN); 57 | gpio_set_dir(BUZZER_PIN, GPIO_OUT); 58 | // Inicializar o PWM no pino do buzzer 59 | pwm_init_buzzer(BUZZER_PIN); 60 | while (true) { 61 | // Verifica o estado do botão 62 | if (gpio_get(BUTTON_PIN) == 0) { // Botão pressionado (nível lógico baixo) 63 | printf("Button pressed\n"); 64 | beep(BUZZER_PIN, 1000); // Bipe de 500ms // Liga o buzzer 65 | // Aguarda 1 segundo 66 | } 67 | } 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /button/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /button/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(button C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(button button.c ) 39 | 40 | pico_set_program_name(button "button") 41 | pico_set_program_version(button "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(button 0) 45 | pico_enable_stdio_usb(button 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(button 49 | pico_stdlib) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(button PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | pico_add_extra_outputs(button) 57 | 58 | -------------------------------------------------------------------------------- /button/button.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Embarcatech 3 | * Exemplo Botão com a BitDogLab 4 | */ 5 | 6 | #include "pico/stdlib.h" 7 | 8 | #define LED_BLUE 12 // GPIO conectado ao terminal azul do LED RGB 9 | #define BUTTON_A 5 // GPIO conectado ao Botão A 10 | 11 | int main() { 12 | // Configuração do GPIO do LED como saída 13 | gpio_init(LED_BLUE); 14 | gpio_set_dir(LED_BLUE, GPIO_OUT); 15 | gpio_put(LED_BLUE, false); // Inicialmente, o LED está apagado 16 | 17 | // Configuração do GPIO do Botão A como entrada com pull-up interno 18 | gpio_init(BUTTON_A); 19 | gpio_set_dir(BUTTON_A, GPIO_IN); 20 | gpio_pull_up(BUTTON_A); 21 | 22 | while (true) { 23 | // Lê o estado do Botão A 24 | bool button_a_state = gpio_get(BUTTON_A); // HIGH = solto, LOW = pressionado 25 | 26 | // Atualiza o estado do LED com base no estado do Botão A 27 | gpio_put(LED_BLUE, button_a_state); // Se solto (HIGH), LED acende; se pressionado (LOW), apaga 28 | 29 | // Pequeno delay para evitar leituras inconsistentes (debounce simples) 30 | sleep_ms(50); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /button/images/button-data_diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/button/images/button-data_diagram.png -------------------------------------------------------------------------------- /button/images/button-fluxograma.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/button/images/button-fluxograma.jpg -------------------------------------------------------------------------------- /button/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /button_led_rgb/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /button_led_rgb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.1.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(button_led_rgb C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(button_led_rgb button_led_rgb.c ) 39 | 40 | pico_set_program_name(button_led_rgb "button_led_rgb") 41 | pico_set_program_version(button_led_rgb "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(button_led_rgb 0) 45 | pico_enable_stdio_usb(button_led_rgb 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(button_led_rgb 49 | pico_stdlib) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(button_led_rgb PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | # Add any user requested libraries 57 | target_link_libraries(button_led_rgb 58 | 59 | ) 60 | 61 | pico_add_extra_outputs(button_led_rgb) 62 | 63 | -------------------------------------------------------------------------------- /button_led_rgb/button_led_rgb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | 4 | int main() { 5 | // Configuração dos pinos dos botões como entrada com pull-up 6 | const uint BUTTON_A_PIN = 5; // Botão A no GPIO 5 7 | const uint BUTTON_B_PIN = 6; // Botão B no GPIO 6 8 | gpio_init(BUTTON_A_PIN); 9 | gpio_init(BUTTON_B_PIN); 10 | gpio_set_dir(BUTTON_A_PIN, GPIO_IN); 11 | gpio_set_dir(BUTTON_B_PIN, GPIO_IN); 12 | gpio_pull_up(BUTTON_A_PIN); 13 | gpio_pull_up(BUTTON_B_PIN); 14 | 15 | // Configuração dos LEDs RGB como saída 16 | const uint BLUE_LED_PIN= 12; // LED azul no GPIO 12 17 | const uint RED_LED_PIN = 13; // LED vermelho no GPIO 13 18 | const uint GREEN_LED_PIN = 11; // LED verde no GPIO 11 19 | gpio_init(RED_LED_PIN); 20 | gpio_init(GREEN_LED_PIN); 21 | gpio_init(BLUE_LED_PIN); 22 | gpio_set_dir(RED_LED_PIN, GPIO_OUT); 23 | gpio_set_dir(GREEN_LED_PIN, GPIO_OUT); 24 | gpio_set_dir(BLUE_LED_PIN, GPIO_OUT); 25 | 26 | // Inicialmente, desligar o LED RGB 27 | gpio_put(RED_LED_PIN, 0); 28 | gpio_put(GREEN_LED_PIN, 0); 29 | gpio_put(BLUE_LED_PIN, 0); 30 | 31 | while (true) { 32 | // Se o botão A for pressionado 33 | if (gpio_get(BUTTON_A_PIN) == 0) { 34 | gpio_put(BLUE_LED_PIN, 0); // Desliga o LED azul 35 | gpio_put(RED_LED_PIN, 1); // Liga o LED vermelho 36 | gpio_put(GREEN_LED_PIN, 0); // Desliga o LED verde 37 | } 38 | // Se o botão B for pressionado 39 | else if (gpio_get(BUTTON_B_PIN) == 0) { 40 | gpio_put(BLUE_LED_PIN, 0); // Desliga o LED azul 41 | gpio_put(RED_LED_PIN, 0); // Desliga o LED vermelho 42 | gpio_put(GREEN_LED_PIN, 1); // Liga o LED verde 43 | } 44 | // Se nenhum botão estiver pressionado 45 | else { 46 | gpio_put(RED_LED_PIN, 0); // Desliga o LED vermelho 47 | gpio_put(GREEN_LED_PIN, 0); // Desliga o LED verde 48 | gpio_put(BLUE_LED_PIN, 0); // Desliga o LED azul 49 | } 50 | sleep_ms(10); // Pequeno atraso para evitar debounce 51 | } 52 | return 0; // O programa nunca alcança essa linha 53 | } 54 | -------------------------------------------------------------------------------- /buzzer/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /buzzer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.1.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(buzzer C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(buzzer buzzer.c ) 39 | 40 | pico_set_program_name(buzzer "buzzer") 41 | pico_set_program_version(buzzer "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(buzzer 0) 45 | pico_enable_stdio_usb(buzzer 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(buzzer 49 | hardware_pwm 50 | pico_stdlib) 51 | 52 | # Add the standard include files to the build 53 | target_include_directories(buzzer PRIVATE 54 | ${CMAKE_CURRENT_LIST_DIR} 55 | ) 56 | 57 | pico_add_extra_outputs(buzzer) 58 | 59 | -------------------------------------------------------------------------------- /buzzer/buzzer.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Exemplo de acionamento de buzzer utilizando sinal PWM no GPIO 21 da Raspberry Pico / BitDog Lab 3 | * 06/12/2024 4 | */ 5 | 6 | #include "pico/stdlib.h" 7 | #include "hardware/pwm.h" 8 | #include "hardware/clocks.h" 9 | 10 | // Configuração do pino do buzzer 11 | #define BUZZER_PIN 21 12 | 13 | // Configuração da frequência do buzzer (em Hz) 14 | #define BUZZER_FREQUENCY 100 15 | 16 | // Definição de uma função para inicializar o PWM no pino do buzzer 17 | void pwm_init_buzzer(uint pin) { 18 | // Configurar o pino como saída de PWM 19 | gpio_set_function(pin, GPIO_FUNC_PWM); 20 | 21 | // Obter o slice do PWM associado ao pino 22 | uint slice_num = pwm_gpio_to_slice_num(pin); 23 | 24 | // Configurar o PWM com frequência desejada 25 | pwm_config config = pwm_get_default_config(); 26 | pwm_config_set_clkdiv(&config, clock_get_hz(clk_sys) / (BUZZER_FREQUENCY * 4096)); // Divisor de clock 27 | pwm_init(slice_num, &config, true); 28 | 29 | // Iniciar o PWM no nível baixo 30 | pwm_set_gpio_level(pin, 0); 31 | } 32 | 33 | // Definição de uma função para emitir um beep com duração especificada 34 | void beep(uint pin, uint duration_ms) { 35 | // Obter o slice do PWM associado ao pino 36 | uint slice_num = pwm_gpio_to_slice_num(pin); 37 | 38 | // Configurar o duty cycle para 50% (ativo) 39 | pwm_set_gpio_level(pin, 2048); 40 | 41 | // Temporização 42 | sleep_ms(duration_ms); 43 | 44 | // Desativar o sinal PWM (duty cycle 0) 45 | pwm_set_gpio_level(pin, 0); 46 | 47 | // Pausa entre os beeps 48 | sleep_ms(100); // Pausa de 100ms 49 | } 50 | 51 | int main() { 52 | // Inicializar o sistema de saída padrão 53 | stdio_init_all(); 54 | 55 | // Inicializar o PWM no pino do buzzer 56 | pwm_init_buzzer(BUZZER_PIN); 57 | 58 | // Loop infinito 59 | while (true) { 60 | beep(BUZZER_PIN, 500); // Bipe de 500ms 61 | } 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /buzzer_pwm1/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /buzzer_pwm1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(buzzer_pwm1 C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(buzzer_pwm1 buzzer_pwm1.c ) 39 | 40 | pico_set_program_name(buzzer_pwm1 "buzzer_pwm1") 41 | pico_set_program_version(buzzer_pwm1 "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(buzzer_pwm1 0) 45 | pico_enable_stdio_usb(buzzer_pwm1 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(buzzer_pwm1 49 | pico_stdlib 50 | hardware_pwm 51 | hardware_clocks) 52 | 53 | # Add the standard include files to the build 54 | target_include_directories(buzzer_pwm1 PRIVATE 55 | ${CMAKE_CURRENT_LIST_DIR} 56 | ) 57 | 58 | # Add any user requested libraries 59 | target_link_libraries(buzzer_pwm1 60 | 61 | ) 62 | 63 | pico_add_extra_outputs(buzzer_pwm1) 64 | 65 | -------------------------------------------------------------------------------- /buzzer_pwm1/buzzer_pwm1.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Exemplo de acionamento do buzzer utilizando sinal PWM no GPIO 21 da Raspberry Pico / BitDogLab 3 | * 06/12/2024 4 | */ 5 | 6 | #include 7 | #include "pico/stdlib.h" 8 | #include "hardware/pwm.h" 9 | #include "hardware/clocks.h" 10 | 11 | // Configuração do pino do buzzer 12 | #define BUZZER_PIN 21 13 | 14 | // Notas musicais para a música tema de Star Wars 15 | const uint star_wars_notes[] = { 16 | 330, 330, 330, 262, 392, 523, 330, 262, 17 | 392, 523, 330, 659, 659, 659, 698, 523, 18 | 415, 349, 330, 262, 392, 523, 330, 262, 19 | 392, 523, 330, 659, 659, 659, 698, 523, 20 | 415, 349, 330, 523, 494, 440, 392, 330, 21 | 659, 784, 659, 523, 494, 440, 392, 330, 22 | 659, 659, 330, 784, 880, 698, 784, 659, 23 | 523, 494, 440, 392, 659, 784, 659, 523, 24 | 494, 440, 392, 330, 659, 523, 659, 262, 25 | 330, 294, 247, 262, 220, 262, 330, 262, 26 | 330, 294, 247, 262, 330, 392, 523, 440, 27 | 349, 330, 659, 784, 659, 523, 494, 440, 28 | 392, 659, 784, 659, 523, 494, 440, 392 29 | }; 30 | 31 | // Duração das notas em milissegundos 32 | const uint note_duration[] = { 33 | 500, 500, 500, 350, 150, 300, 500, 350, 34 | 150, 300, 500, 500, 500, 500, 350, 150, 35 | 300, 500, 500, 350, 150, 300, 500, 350, 36 | 150, 300, 650, 500, 150, 300, 500, 350, 37 | 150, 300, 500, 150, 300, 500, 350, 150, 38 | 300, 650, 500, 350, 150, 300, 500, 350, 39 | 150, 300, 500, 500, 500, 500, 350, 150, 40 | 300, 500, 500, 350, 150, 300, 500, 350, 41 | 150, 300, 500, 350, 150, 300, 500, 500, 42 | 350, 150, 300, 500, 500, 350, 150, 300, 43 | }; 44 | 45 | // Inicializa o PWM no pino do buzzer 46 | void pwm_init_buzzer(uint pin) { 47 | gpio_set_function(pin, GPIO_FUNC_PWM); 48 | uint slice_num = pwm_gpio_to_slice_num(pin); 49 | pwm_config config = pwm_get_default_config(); 50 | pwm_config_set_clkdiv(&config, 4.0f); // Ajusta divisor de clock 51 | pwm_init(slice_num, &config, true); 52 | pwm_set_gpio_level(pin, 0); // Desliga o PWM inicialmente 53 | } 54 | 55 | // Toca uma nota com a frequência e duração especificadas 56 | void play_tone(uint pin, uint frequency, uint duration_ms) { 57 | uint slice_num = pwm_gpio_to_slice_num(pin); 58 | uint32_t clock_freq = clock_get_hz(clk_sys); 59 | uint32_t top = clock_freq / frequency - 1; 60 | 61 | pwm_set_wrap(slice_num, top); 62 | pwm_set_gpio_level(pin, top / 2); // 50% de duty cycle 63 | 64 | sleep_ms(duration_ms); 65 | 66 | pwm_set_gpio_level(pin, 0); // Desliga o som após a duração 67 | sleep_ms(50); // Pausa entre notas 68 | } 69 | 70 | // Função principal para tocar a música 71 | void play_star_wars(uint pin) { 72 | for (int i = 0; i < sizeof(star_wars_notes) / sizeof(star_wars_notes[0]); i++) { 73 | if (star_wars_notes[i] == 0) { 74 | sleep_ms(note_duration[i]); 75 | } else { 76 | play_tone(pin, star_wars_notes[i], note_duration[i]); 77 | } 78 | } 79 | } 80 | 81 | int main() { 82 | stdio_init_all(); 83 | pwm_init_buzzer(BUZZER_PIN); 84 | while(1){ 85 | play_star_wars(BUZZER_PIN); 86 | 87 | } 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /buzzer_pwm1/images/buzzer-diagrama.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/buzzer_pwm1/images/buzzer-diagrama.png -------------------------------------------------------------------------------- /buzzer_pwm1/images/buzzer-fluxograma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/buzzer_pwm1/images/buzzer-fluxograma.png -------------------------------------------------------------------------------- /buzzer_pwm1/images/buzzer-imagem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/buzzer_pwm1/images/buzzer-imagem.png -------------------------------------------------------------------------------- /buzzer_pwm1/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /codigo_modular/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /codigo_modular/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 2.1.1) 19 | set(toolchainVersion 14_2_Rel1) 20 | set(picotoolVersion 2.1.1) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(codigo_modular C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(codigo_modular 39 | app/codigo_modular.c 40 | drivers/led_embutido.c 41 | hal/hal_led.c) 42 | 43 | pico_set_program_name(codigo_modular "codigo_modular") 44 | pico_set_program_version(codigo_modular "0.1") 45 | 46 | # Modify the below lines to enable/disable output over UART/USB 47 | pico_enable_stdio_uart(codigo_modular 0) 48 | pico_enable_stdio_usb(codigo_modular 1) 49 | 50 | # Add the standard library to the build 51 | target_link_libraries(codigo_modular 52 | pico_stdlib 53 | pico_cyw43_arch_none) 54 | 55 | # Add the standard include files to the build 56 | target_include_directories(codigo_modular PRIVATE 57 | ${CMAKE_CURRENT_LIST_DIR} 58 | include) 59 | 60 | # Add any user requested libraries 61 | target_link_libraries(codigo_modular 62 | 63 | ) 64 | 65 | pico_add_extra_outputs(codigo_modular) 66 | 67 | -------------------------------------------------------------------------------- /codigo_modular/app/codigo_modular.c: -------------------------------------------------------------------------------- 1 | // https://datasheets.raspberrypi.com/pico/Pico-R3-A4-Pinout.pdf 2 | // Enunciado: 3 | // A seguir, você encontra um código que inicializa o LED embutido da Raspberry Pi Pico W 4 | // e o faz piscar indefinidamente: 5 | 6 | // #include "pico/stdlib.h" 7 | // #include "pico/cyw43_arch.h" 8 | 9 | // int main() { 10 | // stdio_init_all(); 11 | // if (cyw43_arch_init()) { 12 | // return -1; 13 | // } 14 | 15 | // while (true) { 16 | // cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); 17 | // sleep_ms(500); 18 | // cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); 19 | // sleep_ms(500); 20 | // } 21 | // } 22 | 23 | #include "pico/stdlib.h" 24 | #include "hal_led.h" 25 | 26 | int main() { 27 | hal_led_init(); 28 | 29 | while (true) { 30 | hal_led_toggle(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /codigo_modular/drivers/led_embutido.c: -------------------------------------------------------------------------------- 1 | #include "led_embutido.h" 2 | #include "pico/cyw43_arch.h" 3 | 4 | void led_hw_init() { 5 | cyw43_arch_init(); 6 | } 7 | 8 | void led_hw_on() { 9 | cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); 10 | } 11 | 12 | void led_hw_off() { 13 | cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); 14 | } 15 | -------------------------------------------------------------------------------- /codigo_modular/hal/hal_led.c: -------------------------------------------------------------------------------- 1 | #include "hal_led.h" 2 | #include "led_embutido.h" 3 | #include "pico/stdlib.h" 4 | 5 | void hal_led_init() { 6 | led_hw_init(); 7 | } 8 | 9 | void hal_led_toggle() { 10 | led_hw_on(); 11 | sleep_ms(500); 12 | led_hw_off(); 13 | sleep_ms(500); 14 | } 15 | -------------------------------------------------------------------------------- /codigo_modular/include/hal_led.h: -------------------------------------------------------------------------------- 1 | #ifndef HAL_LED_H 2 | #define HAL_LED_H 3 | 4 | void hal_led_init(); 5 | void hal_led_toggle(); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /codigo_modular/include/led_embutido.h: -------------------------------------------------------------------------------- 1 | #ifndef LED_EMBUTIDO_H 2 | #define LED_EMBUTIDO_H 3 | 4 | void led_hw_init(); 5 | void led_hw_on(); 6 | void led_hw_off(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /display_oled/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /display_oled/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(display_oled C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(display_oled display_oled.c inc/ssd1306_i2c.c) 39 | 40 | pico_set_program_name(display_oled "display_oled") 41 | pico_set_program_version(display_oled "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(display_oled 0) 45 | pico_enable_stdio_usb(display_oled 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(display_oled 49 | pico_stdlib) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(display_oled PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | # Add any user requested libraries 57 | target_link_libraries(display_oled 58 | hardware_i2c 59 | ) 60 | 61 | pico_add_extra_outputs(display_oled) 62 | 63 | -------------------------------------------------------------------------------- /display_oled/images/bitmap_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/display_oled/images/bitmap_info.png -------------------------------------------------------------------------------- /display_oled/inc/ssd1306.h: -------------------------------------------------------------------------------- 1 | #include "ssd1306_i2c.h" 2 | extern void calculate_render_area_buffer_length(struct render_area *area); 3 | extern void ssd1306_send_command(uint8_t cmd); 4 | extern void ssd1306_send_command_list(uint8_t *ssd, int number); 5 | extern void ssd1306_send_buffer(uint8_t ssd[], int buffer_length); 6 | extern void ssd1306_init(); 7 | extern void ssd1306_scroll(bool set); 8 | extern void render_on_display(uint8_t *ssd, struct render_area *area); 9 | extern void ssd1306_set_pixel(uint8_t *ssd, int x, int y, bool set); 10 | extern void ssd1306_draw_line(uint8_t *ssd, int x_0, int y_0, int x_1, int y_1, bool set); 11 | extern void ssd1306_draw_char(uint8_t *ssd, int16_t x, int16_t y, uint8_t character); 12 | extern void ssd1306_draw_string(uint8_t *ssd, int16_t x, int16_t y, char *string); 13 | extern void ssd1306_command(ssd1306_t *ssd, uint8_t command); 14 | extern void ssd1306_config(ssd1306_t *ssd); 15 | extern void ssd1306_init_bm(ssd1306_t *ssd, uint8_t width, uint8_t height, bool external_vcc, uint8_t address, i2c_inst_t *i2c); 16 | extern void ssd1306_send_data(ssd1306_t *ssd); 17 | extern void ssd1306_draw_bitmap(ssd1306_t *ssd, const uint8_t *bitmap); -------------------------------------------------------------------------------- /display_oled/inc/ssd1306_font.h: -------------------------------------------------------------------------------- 1 | 2 | static uint8_t font[] = { 3 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Nothing 4 | 0x78, 0x14, 0x12, 0x11, 0x12, 0x14, 0x78, 0x00, // A 5 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x7f, 0x00, // B 6 | 0x7e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, // C 7 | 0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x7e, 0x00, // D 8 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, // E 9 | 0x7f, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x00, // F 10 | 0x7f, 0x41, 0x41, 0x41, 0x51, 0x51, 0x73, 0x00, // G 11 | 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7f, 0x00, // H 12 | 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, // I 13 | 0x21, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x01, 0x00, // J 14 | 0x00, 0x7f, 0x08, 0x08, 0x14, 0x22, 0x41, 0x00, // K 15 | 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, // L 16 | 0x7f, 0x02, 0x04, 0x08, 0x04, 0x02, 0x7f, 0x00, // M 17 | 0x7f, 0x02, 0x04, 0x08, 0x10, 0x20, 0x7f, 0x00, // N 18 | 0x3e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, 0x00, // O 19 | 0x7f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00, // P 20 | 0x3e, 0x41, 0x41, 0x49, 0x51, 0x61, 0x7e, 0x00, // Q 21 | 0x7f, 0x11, 0x11, 0x11, 0x31, 0x51, 0x0e, 0x00, // R 22 | 0x46, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // S 23 | 0x01, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x01, 0x00, // T 24 | 0x3f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x3f, 0x00, // U 25 | 0x0f, 0x10, 0x20, 0x40, 0x20, 0x10, 0x0f, 0x00, // V 26 | 0x7f, 0x20, 0x10, 0x08, 0x10, 0x20, 0x7f, 0x00, // W 27 | 0x00, 0x41, 0x22, 0x14, 0x14, 0x22, 0x41, 0x00, // X 28 | 0x01, 0x02, 0x04, 0x78, 0x04, 0x02, 0x01, 0x00, // Y 29 | 0x41, 0x61, 0x59, 0x45, 0x43, 0x41, 0x00, 0x00, // Z 30 | 0x3e, 0x41, 0x41, 0x49, 0x41, 0x41, 0x3e, 0x00, // 0 31 | 0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x00, // 1 32 | 0x30, 0x49, 0x49, 0x49, 0x49, 0x46, 0x00, 0x00, // 2 33 | 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 3 34 | 0x3f, 0x20, 0x20, 0x78, 0x20, 0x20, 0x00, 0x00, // 4 35 | 0x4f, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // 5 36 | 0x3f, 0x48, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, // 6 37 | 0x01, 0x01, 0x01, 0x61, 0x31, 0x0d, 0x03, 0x00, // 7 38 | 0x36, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 8 39 | 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x7f, 0x00, // 9 40 | }; -------------------------------------------------------------------------------- /display_oled/inc/ssd1306_i2c.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/i2c.h" 4 | 5 | #ifndef ssd1306_inc_h 6 | #define ssd1306_inc_h 7 | 8 | #define ssd1306_height 64 // Define a altura do display (32 pixels) 9 | #define ssd1306_width 128 // Define a largura do display (128 pixels) 10 | 11 | #define ssd1306_i2c_address _u(0x3C) // Define o endereço do i2c do display 12 | 13 | #define ssd1306_i2c_clock 400 // Define o tempo do clock (pode ser aumentado) 14 | 15 | // Comandos de configuração (endereços) 16 | #define ssd1306_set_memory_mode _u(0x20) 17 | #define ssd1306_set_column_address _u(0x21) 18 | #define ssd1306_set_page_address _u(0x22) 19 | #define ssd1306_set_horizontal_scroll _u(0x26) 20 | #define ssd1306_set_scroll _u(0x2E) 21 | 22 | #define ssd1306_set_display_start_line _u(0x40) 23 | 24 | #define ssd1306_set_contrast _u(0x81) 25 | #define ssd1306_set_charge_pump _u(0x8D) 26 | 27 | #define ssd1306_set_segment_remap _u(0xA0) 28 | #define ssd1306_set_entire_on _u(0xA4) 29 | #define ssd1306_set_all_on _u(0xA5) 30 | #define ssd1306_set_normal_display _u(0xA6) 31 | #define ssd1306_set_inverse_display _u(0xA7) 32 | #define ssd1306_set_mux_ratio _u(0xA8) 33 | #define ssd1306_set_display _u(0xAE) 34 | #define ssd1306_set_common_output_direction _u(0xC0) 35 | #define ssd1306_set_common_output_direction_flip _u(0xC0) 36 | 37 | #define ssd1306_set_display_offset _u(0xD3) 38 | #define ssd1306_set_display_clock_divide_ratio _u(0xD5) 39 | #define ssd1306_set_precharge _u(0xD9) 40 | #define ssd1306_set_common_pin_configuration _u(0xDA) 41 | #define ssd1306_set_vcomh_deselect_level _u(0xDB) 42 | 43 | #define ssd1306_page_height _u(8) 44 | #define ssd1306_n_pages (ssd1306_height / ssd1306_page_height) 45 | #define ssd1306_buffer_length (ssd1306_n_pages * ssd1306_width) 46 | 47 | #define ssd1306_write_mode _u(0xFE) 48 | #define ssd1306_read_mode _u(0xFF) 49 | 50 | struct render_area { 51 | uint8_t start_column; 52 | uint8_t end_column; 53 | uint8_t start_page; 54 | uint8_t end_page; 55 | 56 | int buffer_length; 57 | }; 58 | 59 | typedef struct { 60 | uint8_t width, height, pages, address; 61 | i2c_inst_t * i2c_port; 62 | bool external_vcc; 63 | uint8_t *ram_buffer; 64 | size_t bufsize; 65 | uint8_t port_buffer[2]; 66 | } ssd1306_t; 67 | 68 | #endif -------------------------------------------------------------------------------- /display_oled_logo/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /display_oled_logo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 2.1.0) 8 | set(toolchainVersion 13_3_Rel1) 9 | set(picotoolVersion 2.1.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # Generated Cmake Pico project file 16 | 17 | cmake_minimum_required(VERSION 3.13) 18 | 19 | set(CMAKE_C_STANDARD 11) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Initialise pico_sdk from installed location 24 | # (note this can come from environment, CMake cache etc) 25 | 26 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 27 | if(WIN32) 28 | set(USERHOME $ENV{USERPROFILE}) 29 | else() 30 | set(USERHOME $ENV{HOME}) 31 | endif() 32 | set(sdkVersion 1.5.1) 33 | set(toolchainVersion 13_3_Rel1) 34 | set(picotoolVersion 2.0.0) 35 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 36 | if (EXISTS ${picoVscode}) 37 | include(${picoVscode}) 38 | endif() 39 | # ==================================================================================== 40 | set(PICO_BOARD pico CACHE STRING "Board type") 41 | 42 | # Pull in Raspberry Pi Pico SDK (must be before project) 43 | include(pico_sdk_import.cmake) 44 | 45 | project(display_oled C CXX ASM) 46 | 47 | # Initialise the Raspberry Pi Pico SDK 48 | pico_sdk_init() 49 | 50 | # Add executable. Default name is the project name, version 0.1 51 | 52 | add_executable(display_oled display_oled.c inc/ssd1306_i2c.c) 53 | 54 | pico_set_program_name(display_oled "display_oled") 55 | pico_set_program_version(display_oled "0.1") 56 | 57 | # Modify the below lines to enable/disable output over UART/USB 58 | pico_enable_stdio_uart(display_oled 0) 59 | pico_enable_stdio_usb(display_oled 1) 60 | 61 | # Add the standard library to the build 62 | target_link_libraries(display_oled 63 | pico_stdlib) 64 | 65 | # Add the standard include files to the build 66 | target_include_directories(display_oled PRIVATE 67 | ${CMAKE_CURRENT_LIST_DIR} 68 | ) 69 | 70 | # Add any user requested libraries 71 | target_link_libraries(display_oled 72 | hardware_i2c 73 | ) 74 | 75 | pico_add_extra_outputs(display_oled) 76 | 77 | -------------------------------------------------------------------------------- /display_oled_logo/images/bitmap_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/display_oled_logo/images/bitmap_info.png -------------------------------------------------------------------------------- /display_oled_logo/inc/ssd1306.h: -------------------------------------------------------------------------------- 1 | #include "ssd1306_i2c.h" 2 | extern void calculate_render_area_buffer_length(struct render_area *area); 3 | extern void ssd1306_send_command(uint8_t cmd); 4 | extern void ssd1306_send_command_list(uint8_t *ssd, int number); 5 | extern void ssd1306_send_buffer(uint8_t ssd[], int buffer_length); 6 | extern void ssd1306_init(); 7 | extern void ssd1306_scroll(bool set); 8 | extern void render_on_display(uint8_t *ssd, struct render_area *area); 9 | extern void ssd1306_set_pixel(uint8_t *ssd, int x, int y, bool set); 10 | extern void ssd1306_draw_line(uint8_t *ssd, int x_0, int y_0, int x_1, int y_1, bool set); 11 | extern void ssd1306_draw_char(uint8_t *ssd, int16_t x, int16_t y, uint8_t character); 12 | extern void ssd1306_draw_string(uint8_t *ssd, int16_t x, int16_t y, char *string); 13 | extern void ssd1306_command(ssd1306_t *ssd, uint8_t command); 14 | extern void ssd1306_config(ssd1306_t *ssd); 15 | extern void ssd1306_init_bm(ssd1306_t *ssd, uint8_t width, uint8_t height, bool external_vcc, uint8_t address, i2c_inst_t *i2c); 16 | extern void ssd1306_send_data(ssd1306_t *ssd); 17 | extern void ssd1306_draw_bitmap(ssd1306_t *ssd, const uint8_t *bitmap); -------------------------------------------------------------------------------- /display_oled_logo/inc/ssd1306_font.h: -------------------------------------------------------------------------------- 1 | 2 | static uint8_t font[] = { 3 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Nothing 4 | 0x78, 0x14, 0x12, 0x11, 0x12, 0x14, 0x78, 0x00, // A 5 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x7f, 0x00, // B 6 | 0x7e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, // C 7 | 0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x7e, 0x00, // D 8 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, // E 9 | 0x7f, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x00, // F 10 | 0x7f, 0x41, 0x41, 0x41, 0x51, 0x51, 0x73, 0x00, // G 11 | 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7f, 0x00, // H 12 | 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, // I 13 | 0x21, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x01, 0x00, // J 14 | 0x00, 0x7f, 0x08, 0x08, 0x14, 0x22, 0x41, 0x00, // K 15 | 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, // L 16 | 0x7f, 0x02, 0x04, 0x08, 0x04, 0x02, 0x7f, 0x00, // M 17 | 0x7f, 0x02, 0x04, 0x08, 0x10, 0x20, 0x7f, 0x00, // N 18 | 0x3e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, 0x00, // O 19 | 0x7f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00, // P 20 | 0x3e, 0x41, 0x41, 0x49, 0x51, 0x61, 0x7e, 0x00, // Q 21 | 0x7f, 0x11, 0x11, 0x11, 0x31, 0x51, 0x0e, 0x00, // R 22 | 0x46, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // S 23 | 0x01, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x01, 0x00, // T 24 | 0x3f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x3f, 0x00, // U 25 | 0x0f, 0x10, 0x20, 0x40, 0x20, 0x10, 0x0f, 0x00, // V 26 | 0x7f, 0x20, 0x10, 0x08, 0x10, 0x20, 0x7f, 0x00, // W 27 | 0x00, 0x41, 0x22, 0x14, 0x14, 0x22, 0x41, 0x00, // X 28 | 0x01, 0x02, 0x04, 0x78, 0x04, 0x02, 0x01, 0x00, // Y 29 | 0x41, 0x61, 0x59, 0x45, 0x43, 0x41, 0x00, 0x00, // Z 30 | 0x3e, 0x41, 0x41, 0x49, 0x41, 0x41, 0x3e, 0x00, // 0 31 | 0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x00, // 1 32 | 0x30, 0x49, 0x49, 0x49, 0x49, 0x46, 0x00, 0x00, // 2 33 | 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 3 34 | 0x3f, 0x20, 0x20, 0x78, 0x20, 0x20, 0x00, 0x00, // 4 35 | 0x4f, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // 5 36 | 0x3f, 0x48, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, // 6 37 | 0x01, 0x01, 0x01, 0x61, 0x31, 0x0d, 0x03, 0x00, // 7 38 | 0x36, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 8 39 | 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x7f, 0x00, // 9 40 | }; -------------------------------------------------------------------------------- /display_oled_logo/inc/ssd1306_i2c.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/i2c.h" 4 | 5 | #ifndef ssd1306_inc_h 6 | #define ssd1306_inc_h 7 | 8 | #define ssd1306_height 64 // Define a altura do display (32 pixels) 9 | #define ssd1306_width 128 // Define a largura do display (128 pixels) 10 | 11 | #define ssd1306_i2c_address _u(0x3C) // Define o endereço do i2c do display 12 | 13 | #define ssd1306_i2c_clock 400 // Define o tempo do clock (pode ser aumentado) 14 | 15 | // Comandos de configuração (endereços) 16 | #define ssd1306_set_memory_mode _u(0x20) 17 | #define ssd1306_set_column_address _u(0x21) 18 | #define ssd1306_set_page_address _u(0x22) 19 | #define ssd1306_set_horizontal_scroll _u(0x26) 20 | #define ssd1306_set_scroll _u(0x2E) 21 | 22 | #define ssd1306_set_display_start_line _u(0x40) 23 | 24 | #define ssd1306_set_contrast _u(0x81) 25 | #define ssd1306_set_charge_pump _u(0x8D) 26 | 27 | #define ssd1306_set_segment_remap _u(0xA0) 28 | #define ssd1306_set_entire_on _u(0xA4) 29 | #define ssd1306_set_all_on _u(0xA5) 30 | #define ssd1306_set_normal_display _u(0xA6) 31 | #define ssd1306_set_inverse_display _u(0xA7) 32 | #define ssd1306_set_mux_ratio _u(0xA8) 33 | #define ssd1306_set_display _u(0xAE) 34 | #define ssd1306_set_common_output_direction _u(0xC0) 35 | #define ssd1306_set_common_output_direction_flip _u(0xC0) 36 | 37 | #define ssd1306_set_display_offset _u(0xD3) 38 | #define ssd1306_set_display_clock_divide_ratio _u(0xD5) 39 | #define ssd1306_set_precharge _u(0xD9) 40 | #define ssd1306_set_common_pin_configuration _u(0xDA) 41 | #define ssd1306_set_vcomh_deselect_level _u(0xDB) 42 | 43 | #define ssd1306_page_height _u(8) 44 | #define ssd1306_n_pages (ssd1306_height / ssd1306_page_height) 45 | #define ssd1306_buffer_length (ssd1306_n_pages * ssd1306_width) 46 | 47 | #define ssd1306_write_mode _u(0xFE) 48 | #define ssd1306_read_mode _u(0xFF) 49 | 50 | struct render_area { 51 | uint8_t start_column; 52 | uint8_t end_column; 53 | uint8_t start_page; 54 | uint8_t end_page; 55 | 56 | int buffer_length; 57 | }; 58 | 59 | typedef struct { 60 | uint8_t width, height, pages, address; 61 | i2c_inst_t * i2c_port; 62 | bool external_vcc; 63 | uint8_t *ram_buffer; 64 | size_t bufsize; 65 | uint8_t port_buffer[2]; 66 | } ssd1306_t; 67 | 68 | #endif -------------------------------------------------------------------------------- /goertzel/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /goertzel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(goertzel C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(goertzel goertzel.c ) 39 | 40 | pico_set_program_name(goertzel "goertzel") 41 | pico_set_program_version(goertzel "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(goertzel 0) 45 | pico_enable_stdio_usb(goertzel 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(goertzel 49 | pico_stdlib hardware_adc) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(goertzel PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | pico_add_extra_outputs(goertzel) 57 | 58 | -------------------------------------------------------------------------------- /goertzel/goertzel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "pico/stdlib.h" 4 | #include "hardware/adc.h" 5 | 6 | #define SAMPLE_RATE 2000.0 // Taxa de amostragem em Hz 7 | #define N 400 // Número de amostras 8 | #define TARGET_FREQ 261.0 // Frequência alvo: C4 9 | 10 | float goertzel(float *samples, int num_samples, float target_freq, float sample_rate) 11 | { 12 | float omega = 2.0 * M_PI * target_freq / sample_rate; 13 | float coeff = 2.0 * cos(omega); 14 | 15 | float s_prev = 0.0; 16 | float s_prev2 = 0.0; 17 | float s; 18 | 19 | for (int i = 0; i < num_samples; i++) 20 | { 21 | s = samples[i] + coeff * s_prev - s_prev2; 22 | s_prev2 = s_prev; 23 | s_prev = s; 24 | } 25 | 26 | float power = s_prev2 * s_prev2 + s_prev * s_prev - coeff * s_prev * s_prev2; 27 | return power; 28 | } 29 | 30 | int main() 31 | { 32 | stdio_init_all(); 33 | adc_init(); 34 | adc_gpio_init(28); // Configura GPIO 28 como entrada do ADC 35 | adc_select_input(2); // Usa o canal 2 do ADC 36 | 37 | float samples[N]; 38 | float power; 39 | while (true) 40 | { 41 | for (int i = 0; i < N; i++) 42 | { 43 | uint16_t raw = adc_read(); 44 | samples[i] = (float)raw / 4095.0; // Normaliza a leitura (0 a 1) 45 | // samples[i] = adc_read(); 46 | sleep_us(1000000 / SAMPLE_RATE); // Ajusta a taxa de amostragem 47 | } 48 | 49 | power = goertzel(samples, N, TARGET_FREQ, SAMPLE_RATE); 50 | if (power > 50.0) 51 | printf("Power at %0.1f Hz: %f\n", TARGET_FREQ, power); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /goertzel/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /iot_security_lab/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /iot_security_lab/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 2.1.1) 19 | set(toolchainVersion 14_2_Rel1) 20 | set(picotoolVersion 2.1.1) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(iot_security_lab C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(iot_security_lab iot_security_lab.c 39 | src/mqtt_comm.c 40 | src/wifi_conn.c 41 | src/xor_cipher.c 42 | ) 43 | 44 | pico_set_program_name(iot_security_lab "iot_security_lab") 45 | pico_set_program_version(iot_security_lab "0.1") 46 | 47 | # Modify the below lines to enable/disable output over UART/USB 48 | pico_enable_stdio_uart(iot_security_lab 0) 49 | pico_enable_stdio_usb(iot_security_lab 1) 50 | 51 | # Add the standard library to the build 52 | target_link_libraries(iot_security_lab 53 | # Biblioteca padrão do Pico SDK, que fornece funções básicas para o RP2040 (GPIO, temporizadores, UART, etc.). 54 | pico_stdlib 55 | # Oferece suporte Wi-Fi (CYW43) com LwIP (pilha TCP/IP) em um modo thread-safe em segundo plano. 56 | pico_cyw43_arch_lwip_threadsafe_background 57 | # Adiciona suporte a cliente MQTT sobre o LwIP. 58 | pico_lwip_mqtt 59 | # A pilha Lightweight IP (LwIP), que fornece funcionalidades TCP/IP (HTTP, MQTT, UDP, DHCP, etc.). 60 | pico_lwip 61 | # O driver do chip Wi-Fi CYW43 (usado no Pico W). 62 | pico_cyw43_driver 63 | # pico_time 64 | # pico_unique_id 65 | ) 66 | 67 | # Add the standard include files to the build 68 | target_include_directories(iot_security_lab PRIVATE 69 | ${CMAKE_CURRENT_LIST_DIR} 70 | ) 71 | 72 | # Add any user requested libraries 73 | target_link_libraries(iot_security_lab 74 | 75 | ) 76 | 77 | pico_add_extra_outputs(iot_security_lab) 78 | 79 | -------------------------------------------------------------------------------- /iot_security_lab/include/mqtt_comm.h: -------------------------------------------------------------------------------- 1 | #ifndef MQTT_COMM_H 2 | #define MQTT_COMM_H 3 | void mqtt_setup(const char *client_id, const char *broker_ip, const char *user, const char *pass); 4 | void mqtt_comm_publish(const char *topic, const uint8_t *data, size_t len); 5 | #endif -------------------------------------------------------------------------------- /iot_security_lab/include/wifi_conn.h: -------------------------------------------------------------------------------- 1 | #ifndef WIFI_CONN_H 2 | #define WIFI_CONN_H 3 | void connect_to_wifi(const char *ssid, const char *password); 4 | #endif -------------------------------------------------------------------------------- /iot_security_lab/include/xor_cipher.h: -------------------------------------------------------------------------------- 1 | #ifndef XOR_CIPHER_H 2 | #define XOR_CIPHER_H 3 | #include 4 | #include 5 | void xor_encrypt(const uint8_t *input, uint8_t *output, size_t len, uint8_t key); 6 | #endif -------------------------------------------------------------------------------- /iot_security_lab/iot_security_lab.c: -------------------------------------------------------------------------------- 1 | // Bibliotecas necessárias 2 | #include // Para funções de string como strlen() 3 | #include "pico/stdlib.h" // Biblioteca padrão do Pico (GPIO, tempo, etc.) 4 | #include "pico/cyw43_arch.h" // Driver WiFi para Pico W 5 | #include "include/wifi_conn.h" // Funções personalizadas de conexão WiFi 6 | #include "include/mqtt_comm.h" // Funções personalizadas para MQTT 7 | #include "include/xor_cipher.h" // Funções de cifra XOR 8 | 9 | int main() { 10 | // Inicializa todas as interfaces de I/O padrão (USB serial, etc.) 11 | stdio_init_all(); 12 | 13 | // Conecta à rede WiFi 14 | // Parâmetros: Nome da rede (SSID) e senha 15 | connect_to_wifi("SSID da rede", "Senha da rede"); 16 | 17 | // Configura o cliente MQTT 18 | // Parâmetros: ID do cliente, IP do broker, usuário, senha 19 | mqtt_setup("bitdog1", "IP do broker", "aluno", "senha123"); 20 | 21 | // Mensagem original a ser enviada 22 | const char *mensagem = "26.5"; 23 | // Buffer para mensagem criptografada (16 bytes) 24 | uint8_t criptografada[16]; 25 | // Criptografa a mensagem usando XOR com chave 42 26 | xor_encrypt((uint8_t *)mensagem, criptografada, strlen(mensagem), 42); 27 | 28 | // Loop principal do programa 29 | while (true) { 30 | // Publica a mensagem original (não criptografada) 31 | mqtt_comm_publish("escola/sala1/temperatura", mensagem, strlen(mensagem)); 32 | 33 | // Alternativa: Publica a mensagem criptografada (atualmente comentada) 34 | // mqtt_comm_publish("escola/sala1/temperatura", criptografada, strlen(mensagem)); 35 | 36 | // Aguarda 5 segundos antes da próxima publicação 37 | sleep_ms(5000); 38 | } 39 | return 0; 40 | } 41 | 42 | /* 43 | * Comandos de terminal para testar o MQTT: 44 | * 45 | * Inicia o broker MQTT com logs detalhados: 46 | * mosquitto -c mosquitto.conf -v 47 | * 48 | * Assina o tópico de temperatura (recebe mensagens): 49 | * mosquitto_sub -h localhost -p 1883 -t "escola/sala1/temperatura" -u "aluno" -P "senha123" 50 | * 51 | * Publica mensagem de teste no tópico de temperatura: 52 | * mosquitto_pub -h localhost -p 1883 -t "escola/sala1/temperatura" -u "aluno" -P "senha123" -m "26.6" 53 | */ -------------------------------------------------------------------------------- /iot_security_lab/src/wifi_conn.c: -------------------------------------------------------------------------------- 1 | #include "include/wifi_conn.h" // Cabeçalho com a declaração da função de conexão Wi-Fi 2 | #include "pico/cyw43_arch.h" // Biblioteca para controle do chip Wi-Fi CYW43 no Raspberry Pi Pico W 3 | #include // Biblioteca padrão de entrada/saída (para usar printf) 4 | 5 | /** 6 | * Função: connect_to_wifi 7 | * Objetivo: Inicializar o chip Wi-Fi da Pico W e conectar a uma rede usando SSID e senha fornecidos. 8 | */ 9 | void connect_to_wifi(const char *ssid, const char *password) { 10 | // Inicializa o driver Wi-Fi (CYW43). Retorna 0 se for bem-sucedido. 11 | if (cyw43_arch_init()) { 12 | printf("Erro ao iniciar Wi-Fi\n"); 13 | return; 14 | } 15 | 16 | // Habilita o modo estação (STA) para se conectar a um ponto de acesso. 17 | cyw43_arch_enable_sta_mode(); 18 | 19 | // Tenta conectar à rede Wi-Fi com um tempo limite de 30 segundos (30000 ms). 20 | // Utiliza autenticação WPA2 com criptografia AES. 21 | if (cyw43_arch_wifi_connect_timeout_ms(ssid, password, CYW43_AUTH_WPA2_AES_PSK, 30000)) { 22 | printf("Erro ao conectar\n"); // Se falhar, imprime mensagem de erro. 23 | } else { 24 | printf("Conectado ao Wi-Fi\n"); // Se conectar com sucesso, exibe confirmação. 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /iot_security_lab/src/xor_cipher.c: -------------------------------------------------------------------------------- 1 | // Inclusão do arquivo de cabeçalho que contém a declaração da função 2 | #include "include/xor_cipher.h" 3 | 4 | /** 5 | * Função para aplicar cifra XOR (criptografia/decifração) 6 | * 7 | * @param input Ponteiro para os dados de entrada (texto claro ou cifrado) 8 | * @param output Ponteiro para armazenar o resultado (deve ter tamanho >= len) 9 | * @param len Tamanho dos dados em bytes 10 | * @param key Chave de 1 byte (0-255) para operação XOR 11 | * 12 | * Funcionamento: 13 | * - Aplica operação XOR bit-a-bit entre cada byte do input e a chave 14 | * - XOR é reversível: mesma função para cifrar e decifrar 15 | * - Criptografia fraca (apenas para fins didáticos ou ofuscação básica) 16 | */ 17 | void xor_encrypt(const uint8_t *input, uint8_t *output, size_t len, uint8_t key) { 18 | // Loop por todos os bytes dos dados de entrada 19 | for (size_t i = 0; i < len; ++i) { 20 | // Operação XOR entre o byte atual e a chave 21 | // Armazena resultado no buffer de saída 22 | output[i] = input[i] ^ key; 23 | } 24 | } -------------------------------------------------------------------------------- /isr_count_2btn/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /isr_count_2btn/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 2.1.1) 19 | set(toolchainVersion 14_2_Rel1) 20 | set(picotoolVersion 2.1.1) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(isr_count_2btn C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(isr_count_2btn isr_count_2btn.c inc/ssd1306_i2c.c) 39 | 40 | pico_set_program_name(isr_count_2btn "isr_count_2btn") 41 | pico_set_program_version(isr_count_2btn "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(isr_count_2btn 0) 45 | pico_enable_stdio_usb(isr_count_2btn 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(isr_count_2btn 49 | pico_stdlib) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(isr_count_2btn PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | # Add any user requested libraries 57 | target_link_libraries(isr_count_2btn 58 | hardware_i2c 59 | ) 60 | 61 | pico_add_extra_outputs(isr_count_2btn) 62 | 63 | -------------------------------------------------------------------------------- /isr_count_2btn/inc/ssd1306.h: -------------------------------------------------------------------------------- 1 | #include "ssd1306_i2c.h" 2 | extern void calculate_render_area_buffer_length(struct render_area *area); 3 | extern void ssd1306_send_command(uint8_t cmd); 4 | extern void ssd1306_send_command_list(uint8_t *ssd, int number); 5 | extern void ssd1306_send_buffer(uint8_t ssd[], int buffer_length); 6 | extern void ssd1306_init(); 7 | extern void ssd1306_scroll(bool set); 8 | extern void render_on_display(uint8_t *ssd, struct render_area *area); 9 | extern void ssd1306_set_pixel(uint8_t *ssd, int x, int y, bool set); 10 | extern void ssd1306_draw_line(uint8_t *ssd, int x_0, int y_0, int x_1, int y_1, bool set); 11 | extern void ssd1306_draw_char(uint8_t *ssd, int16_t x, int16_t y, uint8_t character); 12 | extern void ssd1306_draw_string(uint8_t *ssd, int16_t x, int16_t y, char *string); 13 | extern void ssd1306_command(ssd1306_t *ssd, uint8_t command); 14 | extern void ssd1306_config(ssd1306_t *ssd); 15 | extern void ssd1306_init_bm(ssd1306_t *ssd, uint8_t width, uint8_t height, bool external_vcc, uint8_t address, i2c_inst_t *i2c); 16 | extern void ssd1306_send_data(ssd1306_t *ssd); 17 | extern void ssd1306_draw_bitmap(ssd1306_t *ssd, const uint8_t *bitmap); -------------------------------------------------------------------------------- /isr_count_2btn/inc/ssd1306_font.h: -------------------------------------------------------------------------------- 1 | 2 | static uint8_t font[] = { 3 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Nothing 4 | 0x78, 0x14, 0x12, 0x11, 0x12, 0x14, 0x78, 0x00, // A 5 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x7f, 0x00, // B 6 | 0x7e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, // C 7 | 0x7f, 0x41, 0x41, 0x41, 0x41, 0x41, 0x7e, 0x00, // D 8 | 0x7f, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, // E 9 | 0x7f, 0x09, 0x09, 0x09, 0x09, 0x01, 0x01, 0x00, // F 10 | 0x7f, 0x41, 0x41, 0x41, 0x51, 0x51, 0x73, 0x00, // G 11 | 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x7f, 0x00, // H 12 | 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, // I 13 | 0x21, 0x41, 0x41, 0x3f, 0x01, 0x01, 0x01, 0x00, // J 14 | 0x00, 0x7f, 0x08, 0x08, 0x14, 0x22, 0x41, 0x00, // K 15 | 0x7f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, // L 16 | 0x7f, 0x02, 0x04, 0x08, 0x04, 0x02, 0x7f, 0x00, // M 17 | 0x7f, 0x02, 0x04, 0x08, 0x10, 0x20, 0x7f, 0x00, // N 18 | 0x3e, 0x41, 0x41, 0x41, 0x41, 0x41, 0x3e, 0x00, // O 19 | 0x7f, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00, // P 20 | 0x3e, 0x41, 0x41, 0x49, 0x51, 0x61, 0x7e, 0x00, // Q 21 | 0x7f, 0x11, 0x11, 0x11, 0x31, 0x51, 0x0e, 0x00, // R 22 | 0x46, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // S 23 | 0x01, 0x01, 0x01, 0x7f, 0x01, 0x01, 0x01, 0x00, // T 24 | 0x3f, 0x40, 0x40, 0x40, 0x40, 0x40, 0x3f, 0x00, // U 25 | 0x0f, 0x10, 0x20, 0x40, 0x20, 0x10, 0x0f, 0x00, // V 26 | 0x7f, 0x20, 0x10, 0x08, 0x10, 0x20, 0x7f, 0x00, // W 27 | 0x00, 0x41, 0x22, 0x14, 0x14, 0x22, 0x41, 0x00, // X 28 | 0x01, 0x02, 0x04, 0x78, 0x04, 0x02, 0x01, 0x00, // Y 29 | 0x41, 0x61, 0x59, 0x45, 0x43, 0x41, 0x00, 0x00, // Z 30 | 0x3e, 0x41, 0x41, 0x49, 0x41, 0x41, 0x3e, 0x00, // 0 31 | 0x00, 0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, 0x00, // 1 32 | 0x30, 0x49, 0x49, 0x49, 0x49, 0x46, 0x00, 0x00, // 2 33 | 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 3 34 | 0x3f, 0x20, 0x20, 0x78, 0x20, 0x20, 0x00, 0x00, // 4 35 | 0x4f, 0x49, 0x49, 0x49, 0x49, 0x30, 0x00, 0x00, // 5 36 | 0x3f, 0x48, 0x48, 0x48, 0x48, 0x48, 0x30, 0x00, // 6 37 | 0x01, 0x01, 0x01, 0x61, 0x31, 0x0d, 0x03, 0x00, // 7 38 | 0x36, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, // 8 39 | 0x06, 0x09, 0x09, 0x09, 0x09, 0x09, 0x7f, 0x00, // 9 40 | }; -------------------------------------------------------------------------------- /isr_count_2btn/inc/ssd1306_i2c.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/i2c.h" 4 | 5 | #ifndef ssd1306_inc_h 6 | #define ssd1306_inc_h 7 | 8 | #define ssd1306_height 64 // Define a altura do display (64 pixels) 9 | #define ssd1306_width 128 // Define a largura do display (128 pixels) 10 | 11 | #define ssd1306_i2c_address _u(0x3C) // Define o endereço do i2c do display 12 | 13 | #define ssd1306_i2c_clock 400 // Define o tempo do clock (pode ser aumentado) 14 | 15 | // Comandos de configuração (endereços) 16 | #define ssd1306_set_memory_mode _u(0x20) 17 | #define ssd1306_set_column_address _u(0x21) 18 | #define ssd1306_set_page_address _u(0x22) 19 | #define ssd1306_set_horizontal_scroll _u(0x26) 20 | #define ssd1306_set_scroll _u(0x2E) 21 | 22 | #define ssd1306_set_display_start_line _u(0x40) 23 | 24 | #define ssd1306_set_contrast _u(0x81) 25 | #define ssd1306_set_charge_pump _u(0x8D) 26 | 27 | #define ssd1306_set_segment_remap _u(0xA0) 28 | #define ssd1306_set_entire_on _u(0xA4) 29 | #define ssd1306_set_all_on _u(0xA5) 30 | #define ssd1306_set_normal_display _u(0xA6) 31 | #define ssd1306_set_inverse_display _u(0xA7) 32 | #define ssd1306_set_mux_ratio _u(0xA8) 33 | #define ssd1306_set_display _u(0xAE) 34 | #define ssd1306_set_common_output_direction _u(0xC0) 35 | #define ssd1306_set_common_output_direction_flip _u(0xC0) 36 | 37 | #define ssd1306_set_display_offset _u(0xD3) 38 | #define ssd1306_set_display_clock_divide_ratio _u(0xD5) 39 | #define ssd1306_set_precharge _u(0xD9) 40 | #define ssd1306_set_common_pin_configuration _u(0xDA) 41 | #define ssd1306_set_vcomh_deselect_level _u(0xDB) 42 | 43 | #define ssd1306_page_height _u(8) 44 | #define ssd1306_n_pages (ssd1306_height / ssd1306_page_height) 45 | #define ssd1306_buffer_length (ssd1306_n_pages * ssd1306_width) 46 | 47 | #define ssd1306_write_mode _u(0xFE) 48 | #define ssd1306_read_mode _u(0xFF) 49 | 50 | struct render_area { 51 | uint8_t start_column; 52 | uint8_t end_column; 53 | uint8_t start_page; 54 | uint8_t end_page; 55 | 56 | int buffer_length; 57 | }; 58 | 59 | typedef struct { 60 | uint8_t width, height, pages, address; 61 | i2c_inst_t * i2c_port; 62 | bool external_vcc; 63 | uint8_t *ram_buffer; 64 | size_t bufsize; 65 | uint8_t port_buffer[2]; 66 | } ssd1306_t; 67 | 68 | #endif -------------------------------------------------------------------------------- /joystick/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /joystick/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_2_Rel1) 9 | set(picotoolVersion 2.0.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # Generated Cmake Pico project file 16 | 17 | cmake_minimum_required(VERSION 3.13) 18 | 19 | set(CMAKE_C_STANDARD 11) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Initialise pico_sdk from installed location 24 | # (note this can come from environment, CMake cache etc) 25 | 26 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 27 | if(WIN32) 28 | set(USERHOME $ENV{USERPROFILE}) 29 | else() 30 | set(USERHOME $ENV{HOME}) 31 | endif() 32 | set(sdkVersion 1.5.1) 33 | set(toolchainVersion 13_2_Rel1) 34 | set(picotoolVersion 2.0.0) 35 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 36 | if (EXISTS ${picoVscode}) 37 | include(${picoVscode}) 38 | endif() 39 | # ==================================================================================== 40 | set(PICO_BOARD pico CACHE STRING "Board type") 41 | 42 | # Pull in Raspberry Pi Pico SDK (must be before project) 43 | include(pico_sdk_import.cmake) 44 | 45 | project(joystick C CXX ASM) 46 | 47 | # Initialise the Raspberry Pi Pico SDK 48 | pico_sdk_init() 49 | 50 | # Add executable. Default name is the project name, version 0.1 51 | 52 | add_executable(joystick joystick.c ) 53 | 54 | pico_set_program_name(joystick "joystick") 55 | pico_set_program_version(joystick "0.1") 56 | 57 | # Modify the below lines to enable/disable output over UART/USB 58 | pico_enable_stdio_uart(joystick 0) 59 | pico_enable_stdio_usb(joystick 1) 60 | 61 | # Add the standard library to the build 62 | target_link_libraries(joystick 63 | hardware_adc 64 | pico_stdlib) 65 | 66 | # Add the standard include files to the build 67 | target_include_directories(joystick PRIVATE 68 | ${CMAKE_CURRENT_LIST_DIR} 69 | ) 70 | 71 | pico_add_extra_outputs(joystick) 72 | 73 | -------------------------------------------------------------------------------- /joystick/images/joystick-esquema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/joystick/images/joystick-esquema.png -------------------------------------------------------------------------------- /joystick/images/joystick-fluxograma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/joystick/images/joystick-fluxograma.png -------------------------------------------------------------------------------- /joystick/joystick.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "pico/stdlib.h" 9 | #include "hardware/adc.h" 10 | 11 | int main() { 12 | stdio_init_all(); 13 | adc_init(); 14 | // Make sure GPIO is high-impedance, no pullups etc 15 | adc_gpio_init(26); 16 | adc_gpio_init(27); 17 | 18 | while (1) { 19 | adc_select_input(0); 20 | uint adc_y_raw = adc_read(); 21 | adc_select_input(1); 22 | uint adc_x_raw = adc_read(); 23 | 24 | // Display the joystick position something like this: 25 | // X: [ o ] Y: [ o ] 26 | const uint bar_width = 40; 27 | const uint adc_max = (1 << 12) - 1; 28 | uint bar_x_pos = adc_x_raw * bar_width / adc_max; 29 | uint bar_y_pos = adc_y_raw * bar_width / adc_max; 30 | printf("\rX: ["); 31 | for (uint i = 0; i < bar_width; ++i) 32 | putchar( i == bar_x_pos ? 'o' : ' '); 33 | printf("] Y: ["); 34 | for (uint i = 0; i < bar_width; ++i) 35 | putchar( i == bar_y_pos ? 'o' : ' '); 36 | printf("]\n"); 37 | sleep_ms(50); 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /led_rgb/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /led_rgb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(led_rgb C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(led_rgb led_rgb.c ) 39 | 40 | pico_set_program_name(led_rgb "led_rgb") 41 | pico_set_program_version(led_rgb "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(led_rgb 0) 45 | pico_enable_stdio_usb(led_rgb 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(led_rgb 49 | pico_stdlib) 50 | 51 | # Add the standard include files to the build 52 | target_include_directories(led_rgb PRIVATE 53 | ${CMAKE_CURRENT_LIST_DIR} 54 | ) 55 | 56 | # Add any user requested libraries 57 | target_link_libraries(led_rgb 58 | 59 | ) 60 | 61 | pico_add_extra_outputs(led_rgb) 62 | 63 | -------------------------------------------------------------------------------- /led_rgb/images/led_rgb-rgb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/led_rgb/images/led_rgb-rgb.png -------------------------------------------------------------------------------- /led_rgb/images/led_rgb-rgb_variaveis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/led_rgb/images/led_rgb-rgb_variaveis.png -------------------------------------------------------------------------------- /led_rgb/led_rgb.c: -------------------------------------------------------------------------------- 1 | #include "pico/stdlib.h" 2 | 3 | // Função para atualizar os estados dos LEDs 4 | void set_led_color(uint red_pin, uint green_pin, uint blue_pin, bool R, bool G, bool B) { 5 | gpio_put(red_pin, R); // Configura o estado do LED vermelho 6 | gpio_put(green_pin, G); // Configura o estado do LED verde 7 | gpio_put(blue_pin, B); // Configura o estado do LED azul 8 | } 9 | 10 | int main() { 11 | // Configuração dos pinos GPIO 12 | const uint red_pin = 13; // Pino para o LED vermelho 13 | const uint green_pin = 11; // Pino para o LED verde 14 | const uint blue_pin = 12; // Pino para o LED azul 15 | 16 | gpio_init(red_pin); 17 | gpio_init(green_pin); 18 | gpio_init(blue_pin); 19 | 20 | gpio_set_dir(red_pin, GPIO_OUT); 21 | gpio_set_dir(green_pin, GPIO_OUT); 22 | gpio_set_dir(blue_pin, GPIO_OUT); 23 | 24 | // Variáveis binárias para os estados dos LEDs - começa com todos apagados 25 | bool R = 0; // Vermelho 26 | bool G = 0; // Verde 27 | bool B = 0; // Azul 28 | 29 | while (true) { 30 | // Atualiza os LEDs conforme os estados de R, G e B 31 | set_led_color(red_pin, green_pin, blue_pin, R, G, B); 32 | 33 | // Inverte os estados conforme o padrão 34 | B = !B; // Inverte B a cada ciclo 35 | if (B == 0) { // Se B voltar a 0, inverte G 36 | G = !G; 37 | } 38 | if (B == 0 && G == 0) { // Se B e G voltarem a 0, inverte R 39 | R = !R; 40 | } 41 | 42 | sleep_ms(500); // Aguarda 500 ms antes do próximo ciclo 43 | } 44 | 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /led_rgb/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /microphone_dma/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /microphone_dma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_2_Rel1) 9 | set(picotoolVersion 2.0.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # Generated Cmake Pico project file 16 | 17 | cmake_minimum_required(VERSION 3.13) 18 | 19 | set(CMAKE_C_STANDARD 11) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Initialise pico_sdk from installed location 24 | # (note this can come from environment, CMake cache etc) 25 | 26 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 27 | if(WIN32) 28 | set(USERHOME $ENV{USERPROFILE}) 29 | else() 30 | set(USERHOME $ENV{HOME}) 31 | endif() 32 | set(sdkVersion 1.5.1) 33 | set(toolchainVersion 13_3_Rel1) 34 | set(picotoolVersion 2.1.0) 35 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 36 | if (EXISTS ${picoVscode}) 37 | include(${picoVscode}) 38 | endif() 39 | # ==================================================================================== 40 | set(PICO_BOARD pico CACHE STRING "Board type") 41 | 42 | # Pull in Raspberry Pi Pico SDK (must be before project) 43 | include(pico_sdk_import.cmake) 44 | 45 | project(microphone_dma C CXX ASM) 46 | 47 | # Initialise the Raspberry Pi Pico SDK 48 | pico_sdk_init() 49 | 50 | # Add executable. Default name is the project name, version 0.1 51 | 52 | add_executable(microphone_dma microphone_dma.c) 53 | 54 | pico_set_program_name(microphone_dma "microphone_dma") 55 | pico_set_program_version(microphone_dma "0.1") 56 | 57 | # Generate PIO header 58 | pico_generate_pio_header(microphone_dma ${CMAKE_CURRENT_LIST_DIR}/ws2818b.pio) 59 | 60 | # Modify the below lines to enable/disable output over UART/USB 61 | pico_enable_stdio_uart(microphone_dma 0) 62 | pico_enable_stdio_usb(microphone_dma 1) 63 | 64 | # Add the standard library to the build 65 | target_link_libraries(microphone_dma 66 | pico_stdlib) 67 | 68 | # Add the standard include files to the build 69 | target_include_directories(microphone_dma PRIVATE 70 | ${CMAKE_CURRENT_LIST_DIR} 71 | ) 72 | 73 | # Add any user requested libraries 74 | target_link_libraries(microphone_dma 75 | hardware_dma 76 | hardware_timer 77 | hardware_adc 78 | hardware_pio 79 | hardware_clocks 80 | ) 81 | 82 | pico_add_extra_outputs(microphone_dma) 83 | 84 | -------------------------------------------------------------------------------- /microphone_dma/images/microfone_circuito_esquema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/microphone_dma/images/microfone_circuito_esquema.png -------------------------------------------------------------------------------- /microphone_dma/images/microfone_circuito_foto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/microphone_dma/images/microfone_circuito_foto.png -------------------------------------------------------------------------------- /microphone_dma/images/microfone_fluxograma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/microphone_dma/images/microfone_fluxograma.png -------------------------------------------------------------------------------- /microphone_dma/neopixel.c: -------------------------------------------------------------------------------- 1 | #ifndef __NEOPIXEL_INC 2 | #define __NEOPIXEL_INC 3 | 4 | #include 5 | #include "ws2818b.pio.h" 6 | 7 | // Definição de pixel GRB 8 | struct pixel_t { 9 | uint8_t G, R, B; // Três valores de 8-bits compõem um pixel. 10 | }; 11 | typedef struct pixel_t pixel_t; 12 | typedef pixel_t npLED_t; // Mudança de nome de "struct pixel_t" para "npLED_t" por clareza. 13 | 14 | 15 | // Declaração do buffer de pixels que formam a matriz. 16 | static npLED_t *leds; 17 | static uint led_count; 18 | 19 | // Variáveis para uso da máquina PIO. 20 | static PIO np_pio; 21 | static uint np_sm; 22 | 23 | /** 24 | * Inicializa a máquina PIO para controle da matriz de LEDs. 25 | */ 26 | void npInit(uint pin, uint amount) { 27 | 28 | led_count = amount; 29 | leds = (npLED_t *)calloc(led_count, sizeof(npLED_t)); 30 | 31 | // Cria programa PIO. 32 | uint offset = pio_add_program(pio0, &ws2818b_program); 33 | np_pio = pio0; 34 | 35 | // Toma posse de uma máquina PIO. 36 | np_sm = pio_claim_unused_sm(np_pio, false); 37 | if (np_sm < 0) { 38 | np_pio = pio1; 39 | np_sm = pio_claim_unused_sm(np_pio, true); // Se nenhuma máquina estiver livre, panic! 40 | } 41 | 42 | // Inicia programa na máquina PIO obtida. 43 | ws2818b_program_init(np_pio, np_sm, offset, pin, 800000.f); 44 | 45 | // Limpa buffer de pixels. 46 | for (uint i = 0; i < led_count; ++i) { 47 | leds[i].R = 0; 48 | leds[i].G = 0; 49 | leds[i].B = 0; 50 | } 51 | } 52 | 53 | /** 54 | * Atribui uma cor RGB a um LED. 55 | */ 56 | void npSetLED(const uint index, const uint8_t r, const uint8_t g, const uint8_t b) { 57 | leds[index].R = r; 58 | leds[index].G = g; 59 | leds[index].B = b; 60 | } 61 | 62 | /** 63 | * Limpa o buffer de pixels. 64 | */ 65 | void npClear() { 66 | for (uint i = 0; i < led_count; ++i) 67 | npSetLED(i, 0, 0, 0); 68 | } 69 | 70 | /** 71 | * Escreve os dados do buffer nos LEDs. 72 | */ 73 | void npWrite() { 74 | // Escreve cada dado de 8-bits dos pixels em sequência no buffer da máquina PIO. 75 | for (uint i = 0; i < led_count; ++i) { 76 | pio_sm_put_blocking(np_pio, np_sm, leds[i].G); 77 | pio_sm_put_blocking(np_pio, np_sm, leds[i].R); 78 | pio_sm_put_blocking(np_pio, np_sm, leds[i].B); 79 | } 80 | sleep_us(100); // Espera 100us, sinal de RESET do datasheet. 81 | } 82 | 83 | #endif -------------------------------------------------------------------------------- /microphone_dma/ws2818b.pio: -------------------------------------------------------------------------------- 1 | .program ws2818b 2 | .side_set 1 3 | .wrap_target 4 | out x, 1 side 0 [2] 5 | jmp !x, 3 side 1 [1] 6 | jmp 0 side 1 [4] 7 | nop side 0 [4] 8 | .wrap 9 | 10 | 11 | % c-sdk { 12 | void ws2818b_program_init(PIO pio, uint sm, uint offset, uint pin, float freq); 13 | 14 | #ifndef __WS2818B_PROGRAM_INIT_INC 15 | #define __WS2818B_PROGRAM_INIT_INC 16 | 17 | #include "hardware/clocks.h" 18 | 19 | void ws2818b_program_init(PIO pio, uint sm, uint offset, uint pin, float freq) { 20 | 21 | pio_gpio_init(pio, pin); 22 | 23 | pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); 24 | 25 | // Program configuration. 26 | pio_sm_config c = ws2818b_program_get_default_config(offset); 27 | sm_config_set_sideset_pins(&c, pin); // Uses sideset pins. 28 | sm_config_set_out_shift(&c, true, true, 8); // 8 bit transfers, right-shift. 29 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); // Use only TX FIFO. 30 | float prescaler = clock_get_hz(clk_sys) / (10.f * freq); // 10 cycles per transmission, freq is frequency of encoded bits. 31 | sm_config_set_clkdiv(&c, prescaler); 32 | 33 | pio_sm_init(pio, sm, offset, &c); 34 | pio_sm_set_enabled(pio, sm, true); 35 | } 36 | #endif 37 | %} -------------------------------------------------------------------------------- /neopixel_pio/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /neopixel_pio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_2_Rel1) 9 | set(picotoolVersion 2.0.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # Generated Cmake Pico project file 16 | 17 | cmake_minimum_required(VERSION 3.13) 18 | 19 | set(CMAKE_C_STANDARD 11) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Initialise pico_sdk from installed location 24 | # (note this can come from environment, CMake cache etc) 25 | 26 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 27 | if(WIN32) 28 | set(USERHOME $ENV{USERPROFILE}) 29 | else() 30 | set(USERHOME $ENV{HOME}) 31 | endif() 32 | set(sdkVersion 1.5.1) 33 | set(toolchainVersion 13_2_Rel1) 34 | set(picotoolVersion 2.0.0) 35 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 36 | if (EXISTS ${picoVscode}) 37 | include(${picoVscode}) 38 | endif() 39 | # ==================================================================================== 40 | set(PICO_BOARD pico CACHE STRING "Board type") 41 | 42 | # Pull in Raspberry Pi Pico SDK (must be before project) 43 | include(pico_sdk_import.cmake) 44 | 45 | project(neopixel_pio C CXX ASM) 46 | 47 | # Initialise the Raspberry Pi Pico SDK 48 | pico_sdk_init() 49 | 50 | # Add executable. Default name is the project name, version 0.1 51 | 52 | add_executable(neopixel_pio neopixel_pio.c ) 53 | 54 | pico_set_program_name(neopixel_pio "neopixel_pio") 55 | pico_set_program_version(neopixel_pio "0.1") 56 | 57 | # Generate PIO header 58 | pico_generate_pio_header(neopixel_pio ${CMAKE_CURRENT_LIST_DIR}/ws2818b.pio) 59 | 60 | # Modify the below lines to enable/disable output over UART/USB 61 | pico_enable_stdio_uart(neopixel_pio 0) 62 | pico_enable_stdio_usb(neopixel_pio 1) 63 | 64 | # Add the standard library to the build 65 | target_link_libraries(neopixel_pio 66 | pico_stdlib) 67 | 68 | # Add the standard include files to the build 69 | target_include_directories(neopixel_pio PRIVATE 70 | ${CMAKE_CURRENT_LIST_DIR} 71 | ) 72 | 73 | # Add any user requested libraries 74 | target_link_libraries(neopixel_pio 75 | hardware_pio 76 | hardware_clocks 77 | ) 78 | 79 | pico_add_extra_outputs(neopixel_pio) 80 | 81 | -------------------------------------------------------------------------------- /neopixel_pio/docs/neopixel_pio.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/docs/neopixel_pio.drawio.png -------------------------------------------------------------------------------- /neopixel_pio/docs/neopixel_pio_sm.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/docs/neopixel_pio_sm.drawio.png -------------------------------------------------------------------------------- /neopixel_pio/images/2leds_connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/2leds_connection.png -------------------------------------------------------------------------------- /neopixel_pio/images/code_ws2818b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/code_ws2818b.png -------------------------------------------------------------------------------- /neopixel_pio/images/esquema_led_rgb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/esquema_led_rgb.png -------------------------------------------------------------------------------- /neopixel_pio/images/fluxograma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/fluxograma.png -------------------------------------------------------------------------------- /neopixel_pio/images/fluxograma_pio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/fluxograma_pio.png -------------------------------------------------------------------------------- /neopixel_pio/images/led_exercicio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/led_exercicio.png -------------------------------------------------------------------------------- /neopixel_pio/images/matriz_coord_2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/matriz_coord_2_2.png -------------------------------------------------------------------------------- /neopixel_pio/images/matriz_leds_connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/matriz_leds_connection.png -------------------------------------------------------------------------------- /neopixel_pio/images/matriz_vazia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/neopixel_pio/images/matriz_vazia.png -------------------------------------------------------------------------------- /neopixel_pio/neopixel_pio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/pio.h" 4 | #include "hardware/clocks.h" 5 | 6 | // Biblioteca gerada pelo arquivo .pio durante compilação. 7 | #include "ws2818b.pio.h" 8 | 9 | // Definição do número de LEDs e pino. 10 | #define LED_COUNT 25 11 | #define LED_PIN 7 12 | 13 | // Definição de pixel GRB 14 | struct pixel_t { 15 | uint8_t G, R, B; // Três valores de 8-bits compõem um pixel. 16 | }; 17 | typedef struct pixel_t pixel_t; 18 | typedef pixel_t npLED_t; // Mudança de nome de "struct pixel_t" para "npLED_t" por clareza. 19 | 20 | // Declaração do buffer de pixels que formam a matriz. 21 | npLED_t leds[LED_COUNT]; 22 | 23 | // Variáveis para uso da máquina PIO. 24 | PIO np_pio; 25 | uint sm; 26 | 27 | /** 28 | * Inicializa a máquina PIO para controle da matriz de LEDs. 29 | */ 30 | void npInit(uint pin) { 31 | 32 | // Cria programa PIO. 33 | uint offset = pio_add_program(pio0, &ws2818b_program); 34 | np_pio = pio0; 35 | 36 | // Toma posse de uma máquina PIO. 37 | sm = pio_claim_unused_sm(np_pio, false); 38 | if (sm < 0) { 39 | np_pio = pio1; 40 | sm = pio_claim_unused_sm(np_pio, true); // Se nenhuma máquina estiver livre, panic! 41 | } 42 | 43 | // Inicia programa na máquina PIO obtida. 44 | ws2818b_program_init(np_pio, sm, offset, pin, 800000.f); 45 | 46 | // Limpa buffer de pixels. 47 | for (uint i = 0; i < LED_COUNT; ++i) { 48 | leds[i].R = 0; 49 | leds[i].G = 0; 50 | leds[i].B = 0; 51 | } 52 | } 53 | 54 | /** 55 | * Atribui uma cor RGB a um LED. 56 | */ 57 | void npSetLED(const uint index, const uint8_t r, const uint8_t g, const uint8_t b) { 58 | leds[index].R = r; 59 | leds[index].G = g; 60 | leds[index].B = b; 61 | } 62 | 63 | /** 64 | * Limpa o buffer de pixels. 65 | */ 66 | void npClear() { 67 | for (uint i = 0; i < LED_COUNT; ++i) 68 | npSetLED(i, 0, 0, 0); 69 | } 70 | 71 | /** 72 | * Escreve os dados do buffer nos LEDs. 73 | */ 74 | void npWrite() { 75 | // Escreve cada dado de 8-bits dos pixels em sequência no buffer da máquina PIO. 76 | for (uint i = 0; i < LED_COUNT; ++i) { 77 | pio_sm_put_blocking(np_pio, sm, leds[i].G); 78 | pio_sm_put_blocking(np_pio, sm, leds[i].R); 79 | pio_sm_put_blocking(np_pio, sm, leds[i].B); 80 | } 81 | sleep_us(100); // Espera 100us, sinal de RESET do datasheet. 82 | } 83 | 84 | int main() { 85 | 86 | // Inicializa entradas e saídas. 87 | stdio_init_all(); 88 | 89 | // Inicializa matriz de LEDs NeoPixel. 90 | npInit(LED_PIN); 91 | npClear(); 92 | 93 | // Aqui, você desenha nos LEDs. 94 | 95 | npWrite(); // Escreve os dados nos LEDs. 96 | 97 | // Não faz mais nada. Loop infinito. 98 | while (true) { 99 | sleep_ms(1000); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /neopixel_pio/ws2818b.pio: -------------------------------------------------------------------------------- 1 | .program ws2818b 2 | .side_set 1 3 | .wrap_target 4 | out x, 1 side 0 [2] 5 | jmp !x, 3 side 1 [1] 6 | jmp 0 side 1 [4] 7 | nop side 0 [4] 8 | .wrap 9 | 10 | 11 | % c-sdk { 12 | #include "hardware/clocks.h" 13 | 14 | void ws2818b_program_init(PIO pio, uint sm, uint offset, uint pin, float freq) { 15 | 16 | pio_gpio_init(pio, pin); 17 | 18 | pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); 19 | 20 | // Program configuration. 21 | pio_sm_config c = ws2818b_program_get_default_config(offset); 22 | sm_config_set_sideset_pins(&c, pin); // Uses sideset pins. 23 | sm_config_set_out_shift(&c, true, true, 8); // 8 bit transfers, right-shift. 24 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); // Use only TX FIFO. 25 | float prescaler = clock_get_hz(clk_sys) / (10.f * freq); // 10 cycles per transmission, freq is frequency of encoded bits. 26 | sm_config_set_clkdiv(&c, prescaler); 27 | 28 | pio_sm_init(pio, sm, offset, &c); 29 | pio_sm_set_enabled(pio, sm, true); 30 | } 31 | %} -------------------------------------------------------------------------------- /picow_ble_temp_sensor/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /picow_ble_temp_sensor/btstack_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _PICO_BTSTACK_BTSTACK_CONFIG_H 2 | #define _PICO_BTSTACK_BTSTACK_CONFIG_H 3 | 4 | #ifndef ENABLE_BLE 5 | #error Please link to pico_btstack_ble 6 | #endif 7 | 8 | // BTstack features that can be enabled 9 | #define ENABLE_LE_PERIPHERAL 10 | #define ENABLE_LOG_INFO 11 | #define ENABLE_LOG_ERROR 12 | #define ENABLE_PRINTF_HEXDUMP 13 | 14 | // for the client 15 | #if RUNNING_AS_CLIENT 16 | #define ENABLE_LE_CENTRAL 17 | #define MAX_NR_GATT_CLIENTS 1 18 | #else 19 | #define MAX_NR_GATT_CLIENTS 0 20 | #endif 21 | 22 | // BTstack configuration. buffers, sizes, ... 23 | #define HCI_OUTGOING_PRE_BUFFER_SIZE 4 24 | #define HCI_ACL_PAYLOAD_SIZE (255 + 4) 25 | #define HCI_ACL_CHUNK_SIZE_ALIGNMENT 4 26 | #define MAX_NR_HCI_CONNECTIONS 1 27 | #define MAX_NR_SM_LOOKUP_ENTRIES 3 28 | #define MAX_NR_WHITELIST_ENTRIES 16 29 | #define MAX_NR_LE_DEVICE_DB_ENTRIES 16 30 | 31 | // Limit number of ACL/SCO Buffer to use by stack to avoid cyw43 shared bus overrun 32 | #define MAX_NR_CONTROLLER_ACL_BUFFERS 3 33 | #define MAX_NR_CONTROLLER_SCO_PACKETS 3 34 | 35 | // Enable and configure HCI Controller to Host Flow Control to avoid cyw43 shared bus overrun 36 | #define ENABLE_HCI_CONTROLLER_TO_HOST_FLOW_CONTROL 37 | #define HCI_HOST_ACL_PACKET_LEN (255+4) 38 | #define HCI_HOST_ACL_PACKET_NUM 3 39 | #define HCI_HOST_SCO_PACKET_LEN 120 40 | #define HCI_HOST_SCO_PACKET_NUM 3 41 | 42 | // Link Key DB and LE Device DB using TLV on top of Flash Sector interface 43 | #define NVM_NUM_DEVICE_DB_ENTRIES 16 44 | #define NVM_NUM_LINK_KEYS 16 45 | 46 | // We don't give btstack a malloc, so use a fixed-size ATT DB. 47 | #define MAX_ATT_DB_SIZE 512 48 | 49 | // BTstack HAL configuration 50 | #define HAVE_EMBEDDED_TIME_MS 51 | // map btstack_assert onto Pico SDK assert() 52 | #define HAVE_ASSERT 53 | // Some USB dongles take longer to respond to HCI reset (e.g. BCM20702A). 54 | #define HCI_RESET_RESEND_TIMEOUT_MS 1000 55 | #define ENABLE_SOFTWARE_AES128 56 | #define ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS 57 | 58 | #endif // MICROPY_INCLUDED_EXTMOD_BTSTACK_BTSTACK_CONFIG_H 59 | -------------------------------------------------------------------------------- /picow_ble_temp_sensor/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef __LWIPOPTS_H__ 2 | #define __LWIPOPTS_H__ 3 | 4 | // Common settings used in most of the pico_w examples 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) 6 | 7 | // allow override in some examples 8 | #ifndef NO_SYS 9 | #define NO_SYS 1 10 | #endif 11 | // allow override in some examples 12 | #ifndef LWIP_SOCKET 13 | #define LWIP_SOCKET 0 14 | #endif 15 | #if PICO_CYW43_ARCH_POLL 16 | #define MEM_LIBC_MALLOC 1 17 | #else 18 | // MEM_LIBC_MALLOC is incompatible with non polling versions 19 | #define MEM_LIBC_MALLOC 0 20 | #endif 21 | #define MEM_ALIGNMENT 4 22 | #define MEM_SIZE 4000 23 | #define MEMP_NUM_TCP_SEG 32 24 | #define MEMP_NUM_ARP_QUEUE 10 25 | #define PBUF_POOL_SIZE 24 26 | #define LWIP_ARP 1 27 | #define LWIP_ETHERNET 1 28 | #define LWIP_ICMP 1 29 | #define LWIP_RAW 1 30 | #define TCP_WND (8 * TCP_MSS) 31 | #define TCP_MSS 1460 32 | #define TCP_SND_BUF (8 * TCP_MSS) 33 | #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) 34 | #define LWIP_NETIF_STATUS_CALLBACK 1 35 | #define LWIP_NETIF_LINK_CALLBACK 1 36 | #define LWIP_NETIF_HOSTNAME 1 37 | #define LWIP_NETCONN 0 38 | #define MEM_STATS 0 39 | #define SYS_STATS 0 40 | #define MEMP_STATS 0 41 | #define LINK_STATS 0 42 | // #define ETH_PAD_SIZE 2 43 | #define LWIP_CHKSUM_ALGORITHM 3 44 | #define LWIP_DHCP 1 45 | #define LWIP_IPV4 1 46 | #define LWIP_TCP 1 47 | #define LWIP_UDP 1 48 | #define LWIP_DNS 1 49 | #define LWIP_TCP_KEEPALIVE 1 50 | #define LWIP_NETIF_TX_SINGLE_PBUF 1 51 | #define DHCP_DOES_ARP_CHECK 0 52 | #define LWIP_DHCP_DOES_ACD_CHECK 0 53 | 54 | #ifndef NDEBUG 55 | #define LWIP_DEBUG 1 56 | #define LWIP_STATS 1 57 | #define LWIP_STATS_DISPLAY 1 58 | #endif 59 | 60 | #define ETHARP_DEBUG LWIP_DBG_OFF 61 | #define NETIF_DEBUG LWIP_DBG_OFF 62 | #define PBUF_DEBUG LWIP_DBG_OFF 63 | #define API_LIB_DEBUG LWIP_DBG_OFF 64 | #define API_MSG_DEBUG LWIP_DBG_OFF 65 | #define SOCKETS_DEBUG LWIP_DBG_OFF 66 | #define ICMP_DEBUG LWIP_DBG_OFF 67 | #define INET_DEBUG LWIP_DBG_OFF 68 | #define IP_DEBUG LWIP_DBG_OFF 69 | #define IP_REASS_DEBUG LWIP_DBG_OFF 70 | #define RAW_DEBUG LWIP_DBG_OFF 71 | #define MEM_DEBUG LWIP_DBG_OFF 72 | #define MEMP_DEBUG LWIP_DBG_OFF 73 | #define SYS_DEBUG LWIP_DBG_OFF 74 | #define TCP_DEBUG LWIP_DBG_OFF 75 | #define TCP_INPUT_DEBUG LWIP_DBG_OFF 76 | #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF 77 | #define TCP_RTO_DEBUG LWIP_DBG_OFF 78 | #define TCP_CWND_DEBUG LWIP_DBG_OFF 79 | #define TCP_WND_DEBUG LWIP_DBG_OFF 80 | #define TCP_FR_DEBUG LWIP_DBG_OFF 81 | #define TCP_QLEN_DEBUG LWIP_DBG_OFF 82 | #define TCP_RST_DEBUG LWIP_DBG_OFF 83 | #define UDP_DEBUG LWIP_DBG_OFF 84 | #define TCPIP_DEBUG LWIP_DBG_OFF 85 | #define PPP_DEBUG LWIP_DBG_OFF 86 | #define SLIP_DEBUG LWIP_DBG_OFF 87 | #define DHCP_DEBUG LWIP_DBG_OFF 88 | 89 | #endif /* __LWIPOPTS_H__ */ 90 | -------------------------------------------------------------------------------- /picow_ble_temp_sensor/server.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2023 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "btstack.h" 9 | #include "pico/cyw43_arch.h" 10 | #include "pico/btstack_cyw43.h" 11 | #include "hardware/adc.h" 12 | #include "pico/stdlib.h" 13 | 14 | #include "server_common.h" 15 | 16 | #define HEARTBEAT_PERIOD_MS 1000 // Intervalo do timer (1 segundo) 17 | 18 | // Variáveis globais 19 | static btstack_timer_source_t heartbeat; 20 | static btstack_packet_callback_registration_t hci_event_callback_registration; 21 | 22 | // Função chamada periodicamente para atualizar estado do dispositivo 23 | static void heartbeat_handler(struct btstack_timer_source *ts) { 24 | static uint32_t counter = 0; 25 | counter++; 26 | 27 | // Atualizar temperatura a cada 10 segundos 28 | if (counter % 10 == 0) { 29 | poll_temp(); 30 | if (le_notification_enabled) { 31 | att_server_request_can_send_now_event(con_handle); 32 | } 33 | } 34 | 35 | // Alternar o LED da Pico W 36 | static int led_on = true; 37 | led_on = !led_on; 38 | cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, led_on); 39 | 40 | // Reiniciar o timer 41 | btstack_run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS); 42 | btstack_run_loop_add_timer(ts); 43 | } 44 | 45 | int main() { 46 | stdio_init_all(); 47 | 48 | // Inicializar a arquitetura do driver CYW43 (habilita o Bluetooth) 49 | if (cyw43_arch_init()) { 50 | printf("Falha ao inicializar cyw43_arch\n"); 51 | return -1; 52 | } 53 | 54 | // Inicializar o ADC para leitura da temperatura 55 | adc_init(); 56 | adc_select_input(ADC_CHANNEL_TEMPSENSOR); 57 | adc_set_temp_sensor_enabled(true); 58 | 59 | // Inicializar o Bluetooth 60 | l2cap_init(); 61 | sm_init(); 62 | att_server_init(profile_data, att_read_callback, att_write_callback); 63 | 64 | // Registrar callback para eventos do Bluetooth 65 | hci_event_callback_registration.callback = &packet_handler; 66 | hci_add_event_handler(&hci_event_callback_registration); 67 | 68 | // Registrar callback para eventos ATT 69 | att_server_register_packet_handler(packet_handler); 70 | 71 | // Iniciar timer para execução periódica 72 | heartbeat.process = &heartbeat_handler; 73 | btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); 74 | btstack_run_loop_add_timer(&heartbeat); 75 | 76 | // Ligar o Bluetooth 77 | hci_power_control(HCI_POWER_ON); 78 | 79 | // Loop infinito para manter o servidor ativo 80 | while (true) { 81 | sleep_ms(1000); 82 | } 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /picow_ble_temp_sensor/server_common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2023 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #ifndef SERVER_COMMON_H_ 8 | #define SERVER_COMMON_H_ 9 | 10 | #define ADC_CHANNEL_TEMPSENSOR 4 11 | 12 | extern int le_notification_enabled; 13 | extern hci_con_handle_t con_handle; 14 | extern uint16_t current_temp; 15 | extern uint8_t const profile_data[]; 16 | 17 | void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 18 | uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size); 19 | int att_write_callback(hci_con_handle_t connection_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size); 20 | void poll_temp(void); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /picow_ble_temp_sensor/temp_sensor.gatt: -------------------------------------------------------------------------------- 1 | PRIMARY_SERVICE, GAP_SERVICE 2 | CHARACTERISTIC, GAP_DEVICE_NAME, READ, "picow_temp" 3 | 4 | PRIMARY_SERVICE, GATT_SERVICE 5 | CHARACTERISTIC, GATT_DATABASE_HASH, READ, 6 | 7 | PRIMARY_SERVICE, ORG_BLUETOOTH_SERVICE_ENVIRONMENTAL_SENSING 8 | CHARACTERISTIC, ORG_BLUETOOTH_CHARACTERISTIC_TEMPERATURE, READ | NOTIFY | INDICATE | DYNAMIC, 9 | -------------------------------------------------------------------------------- /rgb_pwm/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /rgb_pwm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_2_Rel1) 9 | set(picotoolVersion 2.0.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # Generated Cmake Pico project file 16 | 17 | cmake_minimum_required(VERSION 3.13) 18 | 19 | set(CMAKE_C_STANDARD 11) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Initialise pico_sdk from installed location 24 | # (note this can come from environment, CMake cache etc) 25 | 26 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 27 | if(WIN32) 28 | set(USERHOME $ENV{USERPROFILE}) 29 | else() 30 | set(USERHOME $ENV{HOME}) 31 | endif() 32 | set(sdkVersion 1.5.1) 33 | set(toolchainVersion 13_2_Rel1) 34 | set(picotoolVersion 2.0.0) 35 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 36 | if (EXISTS ${picoVscode}) 37 | include(${picoVscode}) 38 | endif() 39 | # ==================================================================================== 40 | set(PICO_BOARD pico CACHE STRING "Board type") 41 | 42 | # Pull in Raspberry Pi Pico SDK (must be before project) 43 | include(pico_sdk_import.cmake) 44 | 45 | project(rgb_pwm C CXX ASM) 46 | 47 | # Initialise the Raspberry Pi Pico SDK 48 | pico_sdk_init() 49 | 50 | # Add executable. Default name is the project name, version 0.1 51 | 52 | add_executable(rgb_pwm rgb_pwm.c ) 53 | 54 | pico_set_program_name(rgb_pwm "rgb_pwm") 55 | pico_set_program_version(rgb_pwm "0.1") 56 | 57 | # Modify the below lines to enable/disable output over UART/USB 58 | pico_enable_stdio_uart(rgb_pwm 0) 59 | pico_enable_stdio_usb(rgb_pwm 1) 60 | 61 | # Add the standard library to the build 62 | target_link_libraries(rgb_pwm 63 | pico_stdlib) 64 | 65 | # Add the standard include files to the build 66 | target_include_directories(rgb_pwm PRIVATE 67 | ${CMAKE_CURRENT_LIST_DIR} 68 | ) 69 | 70 | # Add any user requested libraries 71 | target_link_libraries(rgb_pwm 72 | hardware_pwm 73 | ) 74 | 75 | pico_add_extra_outputs(rgb_pwm) 76 | 77 | -------------------------------------------------------------------------------- /rgb_pwm/rgb_pwm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/pwm.h" 4 | 5 | #define LEDR 12 6 | #define LEDG 11 7 | #define LEDB 13 8 | 9 | #define PWM_STEP (1 << 8) 10 | 11 | int main() { 12 | stdio_init_all(); 13 | 14 | uint slice_r, slice_g, slice_b; 15 | uint16_t pwm_r = 0xFF00, pwm_g = 0, pwm_b = 0; 16 | uint8_t state = 0; 17 | 18 | gpio_set_function(LEDR, GPIO_FUNC_PWM); 19 | gpio_set_function(LEDG, GPIO_FUNC_PWM); 20 | gpio_set_function(LEDB, GPIO_FUNC_PWM); 21 | 22 | slice_r = pwm_gpio_to_slice_num(LEDR); 23 | slice_g = pwm_gpio_to_slice_num(LEDG); 24 | slice_b = pwm_gpio_to_slice_num(LEDB); 25 | 26 | pwm_config config = pwm_get_default_config(); 27 | pwm_config_set_clkdiv(&config, 4.f); 28 | pwm_init(slice_r, &config, true); 29 | pwm_init(slice_g, &config, true); 30 | pwm_init(slice_b, &config, true); 31 | 32 | pwm_set_gpio_level(LEDR, pwm_r); 33 | pwm_set_gpio_level(LEDG, pwm_g); 34 | pwm_set_gpio_level(LEDB, pwm_b); 35 | 36 | while (true) { 37 | switch (state) { 38 | case 0: 39 | pwm_r -= PWM_STEP; 40 | pwm_g += PWM_STEP; 41 | pwm_set_gpio_level(LEDR, pwm_r); 42 | pwm_set_gpio_level(LEDG, pwm_g); 43 | if (!pwm_r) 44 | state = 1; 45 | break; 46 | case 1: 47 | pwm_g -= PWM_STEP; 48 | pwm_b += PWM_STEP; 49 | pwm_set_gpio_level(LEDG, pwm_g); 50 | pwm_set_gpio_level(LEDB, pwm_b); 51 | if (!pwm_g) 52 | state = 2; 53 | break; 54 | case 2: 55 | pwm_b -= PWM_STEP; 56 | pwm_r += PWM_STEP; 57 | pwm_set_gpio_level(LEDB, pwm_b); 58 | pwm_set_gpio_level(LEDR, pwm_r); 59 | if (!pwm_b) 60 | state = 0; 61 | break; 62 | } 63 | sleep_ms(5); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /rtos-examples/FreeRTOS_Functions_QuickReference.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/rtos-examples/FreeRTOS_Functions_QuickReference.pdf -------------------------------------------------------------------------------- /rtos-examples/Queue/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /rtos-examples/Queue/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | # Pull in FreeRTOS 32 | include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) 33 | 34 | 35 | project(Queue C CXX ASM) 36 | 37 | # Initialise the Raspberry Pi Pico SDK 38 | pico_sdk_init() 39 | 40 | # Add executable. Default name is the project name, version 0.1 41 | 42 | add_executable(Queue Queue.c ) 43 | 44 | pico_set_program_name(Queue "Queue") 45 | pico_set_program_version(Queue "0.1") 46 | 47 | # Modify the below lines to enable/disable output over UART/USB 48 | pico_enable_stdio_uart(Queue 0) 49 | pico_enable_stdio_usb(Queue 1) 50 | 51 | # Add the standard library to the build 52 | target_link_libraries(Queue 53 | pico_stdlib hardware_adc FreeRTOS-Kernel FreeRTOS-Kernel-Heap4) 54 | 55 | # Add the standard include files to the build 56 | target_include_directories(Queue PRIVATE 57 | ${CMAKE_CURRENT_LIST_DIR} 58 | ) 59 | 60 | pico_add_extra_outputs(Queue) 61 | 62 | -------------------------------------------------------------------------------- /rtos-examples/Queue/Queue.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "task.h" 3 | #include "queue.h" 4 | #include "hardware/adc.h" 5 | #include "pico/stdlib.h" 6 | #include 7 | 8 | QueueHandle_t dataQueue; 9 | 10 | float read_onboard_temperature() 11 | { 12 | const float conversion_factor = 3.3f / (1 << 12); // Conversão de 12 bits para tensão 13 | adc_select_input(4); // Seleciona o canal do sensor de temperatura interno (canal 4) 14 | 15 | uint16_t raw_value = adc_read(); // Lê o valor cru do ADC 16 | float voltage = raw_value * conversion_factor; // Converte o valor cru para tensão 17 | 18 | // Fórmula para converter a tensão em temperatura (Celsius) 19 | return 27.0f - (voltage - 0.706f) / 0.001721f; 20 | } 21 | 22 | void vSensorTask(void *pvParameters) 23 | { 24 | float sensorData = 0; 25 | 26 | for (;;) 27 | { 28 | sensorData = read_onboard_temperature(); 29 | xQueueSend(dataQueue, &sensorData, portMAX_DELAY); // Envia dados para a fila 30 | vTaskDelay(1000 / portTICK_PERIOD_MS); // Simula coleta a cada 1s 31 | } 32 | } 33 | 34 | void vProcessingTask(void *pvParameters) 35 | { 36 | float receivedData; 37 | static uint cnt = 0; 38 | static float avg = 0; 39 | 40 | for (;;) 41 | { 42 | if (xQueueReceive(dataQueue, &receivedData, portMAX_DELAY) == pdTRUE) 43 | { 44 | cnt++; 45 | avg += receivedData; 46 | if (cnt == 10) 47 | { 48 | cnt = 0; 49 | avg /= 10; 50 | printf("Media: %f\n", avg); // Processa o dado 51 | avg = 0; 52 | } 53 | } 54 | } 55 | } 56 | 57 | void setup(void) 58 | { 59 | stdio_init_all(); 60 | adc_init(); 61 | adc_set_temp_sensor_enabled(true); 62 | } 63 | 64 | int main() 65 | { 66 | setup(); 67 | 68 | dataQueue = xQueueCreate(5, sizeof(float)); // Fila com capacidade para 5 itens 69 | if (dataQueue != NULL) 70 | { 71 | xTaskCreate(vSensorTask, "Sensor Task", 128, NULL, 1, NULL); 72 | // Tarefas que usam printf precisam ter pilha maior, evite usar printf 73 | // melhor criar uma versão bufferizada com uma Queue :) 74 | xTaskCreate(vProcessingTask, "Processing Task", configMINIMAL_STACK_SIZE * 4, NULL, 1, NULL); 75 | vTaskStartScheduler(); 76 | } 77 | 78 | while (1) 79 | ; 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /rtos-examples/Queue/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /rtos-examples/README.txt: -------------------------------------------------------------------------------- 1 | Exemplos FreeRTOS para BitDogLab 2 | 3 | Este diretório contém cinco exemplos práticos de uso do FreeRTOS para a placa BitDogLab, desenvolvidos para facilitar o aprendizado dos principais recursos do sistema operacional de tempo real. Cada exemplo explora um conceito fundamental do FreeRTOS e como aplicá-lo em projetos embarcados. 4 | 5 | Leia o livro: https://github.com/FreeRTOS/FreeRTOS-Kernel-Book/tree/main 6 | 7 | Requisitos 8 | Placa BitDogLab (Raspberry Pi Pico W) 9 | SDK do Raspberry Pi Pico configurado 10 | FreeRTOS integrado ao ambiente de desenvolvimento (baixe o código no https://freertos.org/ e 11 | configue a variável de ambiente FREERTOS_KERNEL_PATH) 12 | Compilador compatível (ex.: GCC para ARM) 13 | 14 | Exemplos Disponíveis 15 | 1. Blink 16 | Descrição: Faz o LED azul da placa piscar usando uma única tarefa do FreeRTOS. 17 | Conceito: Demonstra o uso básico de tarefas em um sistema de tempo real. 18 | Arquivo: blink.c 19 | 20 | 2. Multitasking 21 | Descrição: Utiliza duas tarefas para alternar o piscar de dois LEDs na placa. 22 | Conceito: Introdução ao multitarefa no FreeRTOS. 23 | Arquivo: multitasking.c 24 | 25 | 3. Queue 26 | Descrição: Implementa uma fila (queue) para transferir dados entre tarefas: 27 | Uma tarefa lê a temperatura do sensor interno e armazena na fila. 28 | Outra tarefa calcula a média das temperaturas armazenadas e imprime o resultado. 29 | Conceito: Demonstra a comunicação entre tarefas utilizando filas no FreeRTOS. 30 | Arquivo: queue.c 31 | 32 | 4. Semáforo 33 | Descrição: 34 | Uma Interrupção de Serviço (ISR), gerada pelo pressionamento do botão, sinaliza um evento via semáforo. 35 | Uma tarefa aguarda o evento do semáforo para acionar o LED. 36 | Conceito: Ilustra a sincronização de eventos entre uma ISR e tarefas usando semáforos. 37 | Arquivo: semaforo.c 38 | 39 | 5. Mutex 40 | Descrição: Duas tarefas compartilham o acesso a um contador utilizando um mutex para evitar condições de disputa. 41 | Conceito: Mostra como proteger recursos compartilhados entre tarefas usando mutexes no FreeRTOS. 42 | Arquivo: mutex.c 43 | 44 | Como Compilar e Executar 45 | Clone este repositório e navegue até o diretório do exemplo desejado. 46 | Compile o código usando o SDK configurado para o Raspberry Pi Pico e FreeRTOS. 47 | Faça o upload do binário para a BitDogLab. 48 | Observe o funcionamento conforme descrito em cada exemplo. -------------------------------------------------------------------------------- /rtos-examples/blink/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /rtos-examples/blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | cmake_minimum_required(VERSION 3.13) 32 | 33 | 34 | 35 | # Pull in FreeRTOS 36 | include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) 37 | 38 | project(blink C CXX ASM) 39 | set(CMAKE_C_STANDARD 11) 40 | set(CMAKE_CXX_STANDARD 17) 41 | 42 | # Initialize the SDK 43 | pico_sdk_init() 44 | 45 | add_executable(blink blink.c) 46 | 47 | target_include_directories(blink PRIVATE ${CMAKE_CURRENT_LIST_DIR}) 48 | 49 | # pull in common dependencies 50 | target_link_libraries(blink pico_stdlib FreeRTOS-Kernel FreeRTOS-Kernel-Heap4) 51 | 52 | pico_enable_stdio_uart(blink 0) 53 | pico_enable_stdio_usb(blink 1) 54 | 55 | # create map/bin/hex/uf2 file etc. 56 | pico_add_extra_outputs(blink) -------------------------------------------------------------------------------- /rtos-examples/blink/blink.c: -------------------------------------------------------------------------------- 1 | #include "pico/stdlib.h" 2 | 3 | #include "FreeRTOS.h" 4 | 5 | #include "task.h" 6 | 7 | #include 8 | 9 | const uint led_pin_red = 12; 10 | 11 | void vBlinkTask() 12 | { 13 | 14 | for (;;) 15 | { 16 | 17 | gpio_put(led_pin_red, 1); 18 | 19 | vTaskDelay(250); 20 | 21 | gpio_put(led_pin_red, 0); 22 | 23 | vTaskDelay(250); 24 | 25 | printf("Blinking\n"); 26 | } 27 | } 28 | 29 | void main() 30 | { 31 | 32 | stdio_init_all(); 33 | 34 | gpio_init(led_pin_red); 35 | 36 | gpio_set_dir(led_pin_red, GPIO_OUT); 37 | 38 | xTaskCreate(vBlinkTask, "Blink Task", 128, NULL, 1, NULL); 39 | 40 | vTaskStartScheduler(); 41 | } -------------------------------------------------------------------------------- /rtos-examples/blink/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /rtos-examples/multitasking/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /rtos-examples/multitasking/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | # Pull in FreeRTOS 32 | include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) 33 | 34 | 35 | project(multitasking C CXX ASM) 36 | 37 | # Initialise the Raspberry Pi Pico SDK 38 | pico_sdk_init() 39 | 40 | # Add executable. Default name is the project name, version 0.1 41 | 42 | add_executable(multitasking multitasking.c ) 43 | 44 | pico_set_program_name(multitasking "multitasking") 45 | pico_set_program_version(multitasking "0.1") 46 | 47 | # Modify the below lines to enable/disable output over UART/USB 48 | pico_enable_stdio_uart(multitasking 0) 49 | pico_enable_stdio_usb(multitasking 1) 50 | 51 | # Add the standard library to the build 52 | target_link_libraries(multitasking 53 | pico_stdlib FreeRTOS-Kernel FreeRTOS-Kernel-Heap4) 54 | 55 | # Add the standard include files to the build 56 | target_include_directories(multitasking PRIVATE 57 | ${CMAKE_CURRENT_LIST_DIR} 58 | ) 59 | 60 | pico_add_extra_outputs(multitasking) 61 | 62 | -------------------------------------------------------------------------------- /rtos-examples/multitasking/multitasking.c: -------------------------------------------------------------------------------- 1 | #include "pico/stdlib.h" 2 | 3 | #include "FreeRTOS.h" 4 | 5 | #include "task.h" 6 | 7 | const uint led_pin_blue = 11; 8 | const uint led_pin_red = 12; 9 | 10 | void setup(void) 11 | { 12 | gpio_init(led_pin_red); 13 | gpio_set_dir(led_pin_red, GPIO_OUT); 14 | gpio_init(led_pin_blue); 15 | gpio_set_dir(led_pin_blue, GPIO_OUT); 16 | } 17 | 18 | void vBlinkTask(void *pvParamters) 19 | { 20 | 21 | uint *led = (uint *)pvParamters; 22 | for (;;) 23 | { 24 | 25 | gpio_put(*led, 1); 26 | 27 | vTaskDelay(250 / portTICK_PERIOD_MS); 28 | 29 | gpio_put(*led, 0); 30 | 31 | vTaskDelay(250 / portTICK_PERIOD_MS); 32 | } 33 | } 34 | 35 | void main(void) 36 | { 37 | 38 | setup(); 39 | 40 | xTaskCreate(vBlinkTask, "Blink Task", 128, (void *)&led_pin_red, 1, NULL); 41 | xTaskCreate(vBlinkTask, "Blink Task 2", 128, (void *)&led_pin_blue, 1, NULL); 42 | 43 | vTaskStartScheduler(); 44 | for (;;) 45 | ; 46 | } -------------------------------------------------------------------------------- /rtos-examples/multitasking/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /rtos-examples/mutex/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /rtos-examples/mutex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | # Pull in FreeRTOS 32 | include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) 33 | 34 | 35 | project(mutex C CXX ASM) 36 | 37 | # Initialise the Raspberry Pi Pico SDK 38 | pico_sdk_init() 39 | 40 | # Add executable. Default name is the project name, version 0.1 41 | 42 | add_executable(mutex mutex.c ) 43 | 44 | pico_set_program_name(mutex "mutex") 45 | pico_set_program_version(mutex "0.1") 46 | 47 | # Modify the below lines to enable/disable output over UART/USB 48 | pico_enable_stdio_uart(mutex 0) 49 | pico_enable_stdio_usb(mutex 1) 50 | 51 | # Add the standard library to the build 52 | target_link_libraries(mutex 53 | pico_stdlib FreeRTOS-Kernel FreeRTOS-Kernel-Heap4) 54 | 55 | # Add the standard include files to the build 56 | target_include_directories(mutex PRIVATE 57 | ${CMAKE_CURRENT_LIST_DIR} 58 | ) 59 | 60 | pico_add_extra_outputs(mutex) 61 | 62 | -------------------------------------------------------------------------------- /rtos-examples/mutex/mutex.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "task.h" 3 | #include "semphr.h" 4 | #include "pico/stdlib.h" 5 | #include 6 | 7 | SemaphoreHandle_t xMutex; 8 | int sharedCounter = 0; 9 | 10 | void vTask1(void *pvParameters) 11 | { 12 | for (;;) 13 | { 14 | // protege a região crítica 15 | if (xSemaphoreTake(xMutex, portMAX_DELAY) == pdTRUE) 16 | { 17 | sharedCounter++; 18 | printf("Task 1: Counter = %d\n", sharedCounter); 19 | xSemaphoreGive(xMutex); 20 | } 21 | vTaskDelay(500 / portTICK_PERIOD_MS); 22 | } 23 | } 24 | 25 | void vTask2(void *pvParameters) 26 | { 27 | for (;;) 28 | { 29 | // protege a região crítica 30 | if (xSemaphoreTake(xMutex, portMAX_DELAY) == pdTRUE) 31 | { 32 | sharedCounter++; 33 | printf("Task 2: Counter = %d\n", sharedCounter); 34 | xSemaphoreGive(xMutex); 35 | } 36 | vTaskDelay(700 / portTICK_PERIOD_MS); 37 | } 38 | } 39 | 40 | int main() 41 | { 42 | stdio_init_all(); 43 | xMutex = xSemaphoreCreateMutex(); 44 | if (xMutex != NULL) 45 | { 46 | xTaskCreate(vTask1, "Task 1", 256, NULL, 1, NULL); 47 | xTaskCreate(vTask2, "Task 2", 256, NULL, 1, NULL); 48 | vTaskStartScheduler(); 49 | } 50 | 51 | while (1) 52 | ; 53 | return 0; 54 | } -------------------------------------------------------------------------------- /rtos-examples/mutex/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /rtos-examples/semaforo/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /rtos-examples/semaforo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_2_Rel1) 20 | set(picotoolVersion 2.0.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | # Pull in FreeRTOS 32 | include($ENV{FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) 33 | 34 | 35 | project(semaforo C CXX ASM) 36 | 37 | # Initialise the Raspberry Pi Pico SDK 38 | pico_sdk_init() 39 | 40 | # Add executable. Default name is the project name, version 0.1 41 | 42 | add_executable(semaforo semaforo.c ) 43 | 44 | pico_set_program_name(semaforo "semaforo") 45 | pico_set_program_version(semaforo "0.1") 46 | 47 | # Modify the below lines to enable/disable output over UART/USB 48 | pico_enable_stdio_uart(semaforo 0) 49 | pico_enable_stdio_usb(semaforo 1) 50 | 51 | # Add the standard library to the build 52 | target_link_libraries(semaforo 53 | pico_stdlib FreeRTOS-Kernel FreeRTOS-Kernel-Heap4) 54 | 55 | # Add the standard include files to the build 56 | target_include_directories(semaforo PRIVATE 57 | ${CMAKE_CURRENT_LIST_DIR} 58 | ) 59 | 60 | pico_add_extra_outputs(semaforo) 61 | 62 | -------------------------------------------------------------------------------- /rtos-examples/semaforo/pico_sdk_import.cmake: -------------------------------------------------------------------------------- 1 | # This is a copy of /external/pico_sdk_import.cmake 2 | 3 | # This can be dropped into an external project to help locate this SDK 4 | # It should be include()ed prior to project() 5 | 6 | if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) 7 | set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) 8 | message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") 9 | endif () 10 | 11 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) 12 | set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) 13 | message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") 14 | endif () 15 | 16 | if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) 17 | set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) 18 | message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") 19 | endif () 20 | 21 | set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") 22 | 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") 23 | set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") 24 | 25 | if (NOT PICO_SDK_PATH) 26 | if (PICO_SDK_FETCH_FROM_GIT) 27 | include(FetchContent) 28 | set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) 29 | if (PICO_SDK_FETCH_FROM_GIT_PATH) 30 | get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") 31 | endif () 32 | # GIT_SUBMODULES_RECURSE was added in 3.17 33 | if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") 34 | FetchContent_Declare( 35 | pico_sdk 36 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 37 | GIT_TAG master 38 | GIT_SUBMODULES_RECURSE FALSE 39 | ) 40 | else () 41 | FetchContent_Declare( 42 | pico_sdk 43 | GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk 44 | GIT_TAG master 45 | ) 46 | endif () 47 | 48 | if (NOT pico_sdk) 49 | message("Downloading Raspberry Pi Pico SDK") 50 | FetchContent_Populate(pico_sdk) 51 | set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) 52 | endif () 53 | set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) 54 | else () 55 | message(FATAL_ERROR 56 | "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." 57 | ) 58 | endif () 59 | endif () 60 | 61 | get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") 62 | if (NOT EXISTS ${PICO_SDK_PATH}) 63 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") 64 | endif () 65 | 66 | set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) 67 | if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) 68 | message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") 69 | endif () 70 | 71 | set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) 72 | 73 | include(${PICO_SDK_INIT_CMAKE_FILE}) 74 | -------------------------------------------------------------------------------- /rtos-examples/semaforo/semaforo.c: -------------------------------------------------------------------------------- 1 | #include "FreeRTOS.h" 2 | #include "task.h" 3 | #include "semphr.h" 4 | #include "pico/stdlib.h" 5 | 6 | #define LED_PIN 12 7 | #define BUTTON_PIN 5 8 | 9 | SemaphoreHandle_t xButtonSemaphore; 10 | 11 | void buttonISR(uint gpio, uint32_t events) 12 | { 13 | BaseType_t xHigherPriorityTaskWoken = pdFALSE; 14 | xSemaphoreGiveFromISR(xButtonSemaphore, &xHigherPriorityTaskWoken); 15 | portYIELD_FROM_ISR(xHigherPriorityTaskWoken); 16 | } 17 | 18 | void vLedTask(void *pvParameters) 19 | { 20 | for (;;) 21 | { 22 | if (xSemaphoreTake(xButtonSemaphore, portMAX_DELAY) == pdTRUE) 23 | { 24 | gpio_put(LED_PIN, 1); // Liga o LED 25 | vTaskDelay(500 / portTICK_PERIOD_MS); 26 | gpio_put(LED_PIN, 0); // Desliga o LED 27 | } 28 | } 29 | } 30 | 31 | void setup(void) 32 | { 33 | stdio_init_all(); 34 | gpio_init(LED_PIN); 35 | gpio_set_dir(LED_PIN, GPIO_OUT); 36 | 37 | gpio_init(BUTTON_PIN); 38 | gpio_set_dir(BUTTON_PIN, GPIO_IN); 39 | gpio_pull_up(BUTTON_PIN); 40 | } 41 | int main() 42 | { 43 | 44 | setup(); 45 | 46 | xButtonSemaphore = xSemaphoreCreateBinary(); 47 | if (xButtonSemaphore != NULL) 48 | { 49 | gpio_set_irq_enabled_with_callback(BUTTON_PIN, GPIO_IRQ_EDGE_FALL, true, buttonISR); 50 | xTaskCreate(vLedTask, "LED Task", 128, NULL, 1, NULL); 51 | vTaskStartScheduler(); 52 | } 53 | 54 | while (1); 55 | return 0; 56 | } -------------------------------------------------------------------------------- /ssd1306/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /ssd1306/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_2_Rel1) 9 | set(picotoolVersion 2.0.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 16 | if(WIN32) 17 | set(USERHOME $ENV{USERPROFILE}) 18 | else() 19 | set(USERHOME $ENV{HOME}) 20 | endif() 21 | set(sdkVersion 1.5.1) 22 | set(toolchainVersion 13_3_Rel1) 23 | set(picotoolVersion 2.1.0) 24 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 25 | if (EXISTS ${picoVscode}) 26 | include(${picoVscode}) 27 | endif() 28 | # ==================================================================================== 29 | # Generated Cmake Pico project file 30 | 31 | cmake_minimum_required(VERSION 3.13) 32 | 33 | set(CMAKE_C_STANDARD 11) 34 | set(CMAKE_CXX_STANDARD 17) 35 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 36 | 37 | # Initialise pico_sdk from installed location 38 | # (note this can come from environment, CMake cache etc) 39 | 40 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 41 | if(WIN32) 42 | set(USERHOME $ENV{USERPROFILE}) 43 | else() 44 | set(USERHOME $ENV{HOME}) 45 | endif() 46 | set(sdkVersion 2.1.0) 47 | set(toolchainVersion 13_3_Rel1) 48 | set(picotoolVersion 2.1.0) 49 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 50 | if (EXISTS ${picoVscode}) 51 | include(${picoVscode}) 52 | endif() 53 | # ==================================================================================== 54 | set(PICO_BOARD pico CACHE STRING "Board type") 55 | 56 | # Pull in Raspberry Pi Pico SDK (must be before project) 57 | include(pico_sdk_import.cmake) 58 | 59 | project(ssd1306 C CXX ASM) 60 | 61 | # Initialise the Raspberry Pi Pico SDK 62 | pico_sdk_init() 63 | 64 | # Add executable. Default name is the project name, version 0.1 65 | 66 | add_executable(ssd1306 ssd1306.c inc/ssd1306.c) 67 | 68 | pico_set_program_name(ssd1306 "ssd1306") 69 | pico_set_program_version(ssd1306 "0.1") 70 | 71 | # Modify the below lines to enable/disable output over UART/USB 72 | pico_enable_stdio_uart(ssd1306 0) 73 | pico_enable_stdio_usb(ssd1306 1) 74 | 75 | # Add the standard library to the build 76 | target_link_libraries(ssd1306 77 | pico_stdlib) 78 | 79 | # Add the standard include files to the build 80 | target_include_directories(ssd1306 PRIVATE 81 | ${CMAKE_CURRENT_LIST_DIR} 82 | ) 83 | 84 | # Add any user requested libraries 85 | target_link_libraries(ssd1306 86 | hardware_i2c 87 | ) 88 | 89 | pico_add_extra_outputs(ssd1306) 90 | 91 | -------------------------------------------------------------------------------- /ssd1306/inc/ssd1306.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pico/stdlib.h" 3 | #include "hardware/i2c.h" 4 | 5 | #define WIDTH 128 6 | #define HEIGHT 64 7 | 8 | typedef enum { 9 | SET_CONTRAST = 0x81, 10 | SET_ENTIRE_ON = 0xA4, 11 | SET_NORM_INV = 0xA6, 12 | SET_DISP = 0xAE, 13 | SET_MEM_ADDR = 0x20, 14 | SET_COL_ADDR = 0x21, 15 | SET_PAGE_ADDR = 0x22, 16 | SET_DISP_START_LINE = 0x40, 17 | SET_SEG_REMAP = 0xA0, 18 | SET_MUX_RATIO = 0xA8, 19 | SET_COM_OUT_DIR = 0xC0, 20 | SET_DISP_OFFSET = 0xD3, 21 | SET_COM_PIN_CFG = 0xDA, 22 | SET_DISP_CLK_DIV = 0xD5, 23 | SET_PRECHARGE = 0xD9, 24 | SET_VCOM_DESEL = 0xDB, 25 | SET_CHARGE_PUMP = 0x8D 26 | } ssd1306_command_t; 27 | 28 | typedef struct { 29 | uint8_t width, height, pages, address; 30 | i2c_inst_t *i2c_port; 31 | bool external_vcc; 32 | uint8_t *ram_buffer; 33 | size_t bufsize; 34 | uint8_t port_buffer[2]; 35 | } ssd1306_t; 36 | 37 | void ssd1306_init(ssd1306_t *ssd, uint8_t width, uint8_t height, bool external_vcc, uint8_t address, i2c_inst_t *i2c); 38 | void ssd1306_config(ssd1306_t *ssd); 39 | void ssd1306_command(ssd1306_t *ssd, uint8_t command); 40 | void ssd1306_send_data(ssd1306_t *ssd); 41 | 42 | void ssd1306_pixel(ssd1306_t *ssd, uint8_t x, uint8_t y, bool value); 43 | void ssd1306_fill(ssd1306_t *ssd, bool value); 44 | void ssd1306_rect(ssd1306_t *ssd, uint8_t top, uint8_t left, uint8_t width, uint8_t height, bool value, bool fill); 45 | void ssd1306_line(ssd1306_t *ssd, uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, bool value); 46 | void ssd1306_hline(ssd1306_t *ssd, uint8_t x0, uint8_t x1, uint8_t y, bool value); 47 | void ssd1306_vline(ssd1306_t *ssd, uint8_t x, uint8_t y0, uint8_t y1, bool value); -------------------------------------------------------------------------------- /ssd1306/ssd1306.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "pico/stdlib.h" 4 | #include "hardware/i2c.h" 5 | #include "inc/ssd1306.h" 6 | 7 | #define I2C_PORT i2c1 8 | #define I2C_SDA 14 9 | #define I2C_SCL 15 10 | 11 | int main() { 12 | stdio_init_all(); 13 | 14 | // I2C Initialisation. Using it at 400Khz. 15 | i2c_init(I2C_PORT, 400*1000); 16 | 17 | gpio_set_function(I2C_SDA, GPIO_FUNC_I2C); 18 | gpio_set_function(I2C_SCL, GPIO_FUNC_I2C); 19 | gpio_pull_up(I2C_SDA); 20 | gpio_pull_up(I2C_SCL); 21 | 22 | ssd1306_t ssd; 23 | 24 | ssd1306_init(&ssd, WIDTH, HEIGHT, false, 0x3C, I2C_PORT); 25 | ssd1306_config(&ssd); 26 | 27 | ssd1306_send_data(&ssd); 28 | 29 | ssd1306_fill(&ssd, false); 30 | ssd1306_hline(&ssd, 0, 127, 32, true); 31 | ssd1306_vline(&ssd, 63, 0, 63, true); 32 | //ssd1306_draw_string(&ssd, 0, 0, "Bem-vindos!"); 33 | //ssd1306_draw_string(&ssd, 0, 10, "Embarcatech"); 34 | ssd1306_send_data(&ssd); // Atualiza o display 35 | 36 | ssd1306_draw_string(&ssd, 0, 0, "Bem-vindos!"); 37 | ssd1306_draw_string(&ssd, 0, 10, "Embarcatech"); 38 | ssd1306_send_data(&ssd); // Atualiza o display 39 | 40 | ssd1306_send_data(&ssd); 41 | 42 | while (true) { 43 | sleep_ms(1000); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /unit_test_temp/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /unit_test_temp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 2.1.1) 19 | set(toolchainVersion 14_2_Rel1) 20 | set(picotoolVersion 2.1.1) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(unit_test_temp C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Adicione diretórios necessários 37 | add_subdirectory(lib/unity) 38 | 39 | # Add executable. Default name is the project name, version 0.1 40 | 41 | add_executable(unit_test_temp unit_test_temp.c ) 42 | 43 | pico_set_program_name(unit_test_temp "unit_test_temp") 44 | pico_set_program_version(unit_test_temp "0.1") 45 | 46 | # Modify the below lines to enable/disable output over UART/USB 47 | pico_enable_stdio_uart(unit_test_temp 0) 48 | pico_enable_stdio_usb(unit_test_temp 1) 49 | 50 | # Add the standard library to the build 51 | target_link_libraries(unit_test_temp 52 | pico_stdlib) 53 | 54 | # Add the standard include files to the build 55 | target_include_directories(unit_test_temp PRIVATE 56 | ${CMAKE_CURRENT_LIST_DIR} 57 | lib/unity) 58 | 59 | # Add any user requested libraries 60 | target_link_libraries(unit_test_temp 61 | unity::framework 62 | ) 63 | 64 | pico_add_extra_outputs(unit_test_temp) 65 | 66 | -------------------------------------------------------------------------------- /unit_test_temp/unit_test_temp.c: -------------------------------------------------------------------------------- 1 | // Implemente uma função de teste unitário em C para verificar se uma função de cálculo de temperatura retorna 2 | // corretamente valores em graus Celsius. 3 | 4 | #include 5 | #include "pico/stdlib.h" 6 | // https://www.throwtheswitch.org/unity 7 | #include "unity.h" 8 | 9 | void setUp(void) { 10 | // Configuração inicial, se necessário 11 | } 12 | 13 | void tearDown(void) { 14 | // Limpeza, se necessário 15 | } 16 | 17 | float adc_to_celsius(uint16_t raw_adc) { 18 | const float conversion_factor = 3.3f / 4095; 19 | float voltage = raw_adc * conversion_factor; 20 | return 27 - (voltage - 0.706f) / 0.001721f; 21 | } 22 | 23 | void test_adc_to_celsius_should_return_27_when_voltage_is_0_706() { 24 | uint16_t raw_adc = (uint16_t)(0.706f / (3.3f / 4095)); // Mock - Inverso da conversão 25 | float temp = adc_to_celsius(raw_adc); 26 | TEST_ASSERT_FLOAT_WITHIN(0.1, 27.0f, temp); 27 | } 28 | 29 | int main(void) { 30 | stdio_init_all(); // Inicializa a comunicação serial 31 | sleep_ms(3000); // Aguarda a USB conectar (opcional, mas útil) 32 | 33 | while (true) { 34 | printf("Iniciando testes Unity...\n"); 35 | 36 | UNITY_BEGIN(); 37 | RUN_TEST(test_adc_to_celsius_should_return_27_when_voltage_is_0_706); 38 | UNITY_END(); 39 | 40 | printf("Testes finalizados. Reiniciando em 5 segundos...\n---\n"); 41 | sleep_ms(5000); 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /wifi_button_and_led/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /wifi_button_and_led/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 2 | if(WIN32) 3 | set(USERHOME $ENV{USERPROFILE}) 4 | else() 5 | set(USERHOME $ENV{HOME}) 6 | endif() 7 | set(sdkVersion 1.5.1) 8 | set(toolchainVersion 13_3_Rel1) 9 | set(picotoolVersion 2.1.0) 10 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 11 | if (EXISTS ${picoVscode}) 12 | include(${picoVscode}) 13 | endif() 14 | # ==================================================================================== 15 | # Generated Cmake Pico project file 16 | 17 | cmake_minimum_required(VERSION 3.13) 18 | 19 | set(CMAKE_C_STANDARD 11) 20 | set(CMAKE_CXX_STANDARD 17) 21 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 22 | 23 | # Initialise pico_sdk from installed location 24 | # (note this can come from environment, CMake cache etc) 25 | 26 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 27 | if(WIN32) 28 | set(USERHOME $ENV{USERPROFILE}) 29 | else() 30 | set(USERHOME $ENV{HOME}) 31 | endif() 32 | set(sdkVersion 2.1.0) 33 | set(toolchainVersion 13_3_Rel1) 34 | set(picotoolVersion 2.1.0) 35 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 36 | if (EXISTS ${picoVscode}) 37 | include(${picoVscode}) 38 | endif() 39 | # ==================================================================================== 40 | set(PICO_BOARD pico_w CACHE STRING "Board type") 41 | 42 | # Pull in Raspberry Pi Pico SDK (must be before project) 43 | include(pico_sdk_import.cmake) 44 | 45 | project(pico_w_wifi_complete_example C CXX ASM) 46 | 47 | # Initialise the Raspberry Pi Pico SDK 48 | pico_sdk_init() 49 | 50 | # Add executable. Default name is the project name, version 0.1 51 | 52 | add_executable(pico_w_wifi_complete_example pico_w_wifi_complete_example.c ) 53 | 54 | pico_set_program_name(pico_w_wifi_complete_example "pico_w_wifi_complete_example") 55 | pico_set_program_version(pico_w_wifi_complete_example "0.1") 56 | 57 | # Modify the below lines to enable/disable output over UART/USB 58 | pico_enable_stdio_uart(pico_w_wifi_complete_example 0) 59 | pico_enable_stdio_usb(pico_w_wifi_complete_example 1) 60 | 61 | # Add the standard library to the build 62 | target_link_libraries(pico_w_wifi_complete_example 63 | pico_stdlib) 64 | 65 | # Add the standard include files to the build 66 | target_include_directories(pico_w_wifi_complete_example PRIVATE 67 | ${CMAKE_CURRENT_LIST_DIR} 68 | ) 69 | 70 | # Add any user requested libraries 71 | target_link_libraries(pico_w_wifi_complete_example 72 | pico_cyw43_arch_lwip_threadsafe_background 73 | ) 74 | 75 | pico_add_extra_outputs(pico_w_wifi_complete_example) 76 | 77 | -------------------------------------------------------------------------------- /wifi_button_and_led/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef __LWIPOPTS_H__ 2 | #define __LWIPOPTS_H__ 3 | 4 | // Common settings used in most of the pico_w examples 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) 6 | 7 | // allow override in some examples 8 | #ifndef NO_SYS 9 | #define NO_SYS 1 10 | #endif 11 | // allow override in some examples 12 | #ifndef LWIP_SOCKET 13 | #define LWIP_SOCKET 0 14 | #endif 15 | #if PICO_CYW43_ARCH_POLL 16 | #define MEM_LIBC_MALLOC 1 17 | #else 18 | // MEM_LIBC_MALLOC is incompatible with non polling versions 19 | #define MEM_LIBC_MALLOC 0 20 | #endif 21 | #define MEM_ALIGNMENT 4 22 | #define MEM_SIZE 4000 23 | #define MEMP_NUM_TCP_SEG 32 24 | #define MEMP_NUM_ARP_QUEUE 10 25 | #define PBUF_POOL_SIZE 24 26 | #define LWIP_ARP 1 27 | #define LWIP_ETHERNET 1 28 | #define LWIP_ICMP 1 29 | #define LWIP_RAW 1 30 | #define TCP_WND (8 * TCP_MSS) 31 | #define TCP_MSS 1460 32 | #define TCP_SND_BUF (8 * TCP_MSS) 33 | #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) 34 | #define LWIP_NETIF_STATUS_CALLBACK 1 35 | #define LWIP_NETIF_LINK_CALLBACK 1 36 | #define LWIP_NETIF_HOSTNAME 1 37 | #define LWIP_NETCONN 0 38 | #define MEM_STATS 0 39 | #define SYS_STATS 0 40 | #define MEMP_STATS 0 41 | #define LINK_STATS 0 42 | // #define ETH_PAD_SIZE 2 43 | #define LWIP_CHKSUM_ALGORITHM 3 44 | #define LWIP_DHCP 1 45 | #define LWIP_IPV4 1 46 | #define LWIP_TCP 1 47 | #define LWIP_UDP 1 48 | #define LWIP_DNS 1 49 | #define LWIP_TCP_KEEPALIVE 1 50 | #define LWIP_NETIF_TX_SINGLE_PBUF 1 51 | #define DHCP_DOES_ARP_CHECK 0 52 | #define LWIP_DHCP_DOES_ACD_CHECK 0 53 | 54 | #ifndef NDEBUG 55 | #define LWIP_DEBUG 1 56 | #define LWIP_STATS 1 57 | #define LWIP_STATS_DISPLAY 1 58 | #endif 59 | 60 | #define ETHARP_DEBUG LWIP_DBG_OFF 61 | #define NETIF_DEBUG LWIP_DBG_OFF 62 | #define PBUF_DEBUG LWIP_DBG_OFF 63 | #define API_LIB_DEBUG LWIP_DBG_OFF 64 | #define API_MSG_DEBUG LWIP_DBG_OFF 65 | #define SOCKETS_DEBUG LWIP_DBG_OFF 66 | #define ICMP_DEBUG LWIP_DBG_OFF 67 | #define INET_DEBUG LWIP_DBG_OFF 68 | #define IP_DEBUG LWIP_DBG_OFF 69 | #define IP_REASS_DEBUG LWIP_DBG_OFF 70 | #define RAW_DEBUG LWIP_DBG_OFF 71 | #define MEM_DEBUG LWIP_DBG_OFF 72 | #define MEMP_DEBUG LWIP_DBG_OFF 73 | #define SYS_DEBUG LWIP_DBG_OFF 74 | #define TCP_DEBUG LWIP_DBG_OFF 75 | #define TCP_INPUT_DEBUG LWIP_DBG_OFF 76 | #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF 77 | #define TCP_RTO_DEBUG LWIP_DBG_OFF 78 | #define TCP_CWND_DEBUG LWIP_DBG_OFF 79 | #define TCP_WND_DEBUG LWIP_DBG_OFF 80 | #define TCP_FR_DEBUG LWIP_DBG_OFF 81 | #define TCP_QLEN_DEBUG LWIP_DBG_OFF 82 | #define TCP_RST_DEBUG LWIP_DBG_OFF 83 | #define UDP_DEBUG LWIP_DBG_OFF 84 | #define TCPIP_DEBUG LWIP_DBG_OFF 85 | #define PPP_DEBUG LWIP_DBG_OFF 86 | #define SLIP_DEBUG LWIP_DBG_OFF 87 | #define DHCP_DEBUG LWIP_DBG_OFF 88 | 89 | #endif /* __LWIPOPTS_H__ */ 90 | -------------------------------------------------------------------------------- /wifi_led/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /wifi_led/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated Cmake Pico project file 2 | 3 | cmake_minimum_required(VERSION 3.13) 4 | 5 | set(CMAKE_C_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 8 | 9 | # Initialise pico_sdk from installed location 10 | # (note this can come from environment, CMake cache etc) 11 | 12 | # == DO NOT EDIT THE FOLLOWING LINES for the Raspberry Pi Pico VS Code Extension to work == 13 | if(WIN32) 14 | set(USERHOME $ENV{USERPROFILE}) 15 | else() 16 | set(USERHOME $ENV{HOME}) 17 | endif() 18 | set(sdkVersion 1.5.1) 19 | set(toolchainVersion 13_3_Rel1) 20 | set(picotoolVersion 2.1.0) 21 | set(picoVscode ${USERHOME}/.pico-sdk/cmake/pico-vscode.cmake) 22 | if (EXISTS ${picoVscode}) 23 | include(${picoVscode}) 24 | endif() 25 | # ==================================================================================== 26 | set(PICO_BOARD pico_w CACHE STRING "Board type") 27 | 28 | # Pull in Raspberry Pi Pico SDK (must be before project) 29 | include(pico_sdk_import.cmake) 30 | 31 | project(pico_w_wifi_example C CXX ASM) 32 | 33 | # Initialise the Raspberry Pi Pico SDK 34 | pico_sdk_init() 35 | 36 | # Add executable. Default name is the project name, version 0.1 37 | 38 | add_executable(pico_w_wifi_example pico_w_wifi_example.c ) 39 | 40 | pico_set_program_name(pico_w_wifi_example "pico_w_wifi_example") 41 | pico_set_program_version(pico_w_wifi_example "0.1") 42 | 43 | # Modify the below lines to enable/disable output over UART/USB 44 | pico_enable_stdio_uart(pico_w_wifi_example 0) 45 | pico_enable_stdio_usb(pico_w_wifi_example 1) 46 | 47 | # Add the standard library to the build 48 | target_link_libraries(pico_w_wifi_example 49 | pico_stdlib 50 | pico_cyw43_arch_lwip_threadsafe_background 51 | ) 52 | 53 | # Add the standard include files to the build 54 | target_include_directories(pico_w_wifi_example PRIVATE 55 | ${CMAKE_CURRENT_LIST_DIR} 56 | ) 57 | 58 | pico_add_extra_outputs(pico_w_wifi_example) 59 | 60 | -------------------------------------------------------------------------------- /wifi_led/images/fluxograma_wifi_led.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/wifi_led/images/fluxograma_wifi_led.png -------------------------------------------------------------------------------- /wifi_led/images/print_tela_wifi_http.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BitDogLab/BitDogLab-C/476c8508b55d1c4478705f073ff51d21576ae389/wifi_led/images/print_tela_wifi_http.png -------------------------------------------------------------------------------- /wifi_led/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef __LWIPOPTS_H__ 2 | #define __LWIPOPTS_H__ 3 | 4 | // Common settings used in most of the pico_w examples 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html for details) 6 | 7 | // allow override in some examples 8 | #ifndef NO_SYS 9 | #define NO_SYS 1 10 | #endif 11 | // allow override in some examples 12 | #ifndef LWIP_SOCKET 13 | #define LWIP_SOCKET 0 14 | #endif 15 | #if PICO_CYW43_ARCH_POLL 16 | #define MEM_LIBC_MALLOC 1 17 | #else 18 | // MEM_LIBC_MALLOC is incompatible with non polling versions 19 | #define MEM_LIBC_MALLOC 0 20 | #endif 21 | #define MEM_ALIGNMENT 4 22 | #define MEM_SIZE 4000 23 | #define MEMP_NUM_TCP_SEG 32 24 | #define MEMP_NUM_ARP_QUEUE 10 25 | #define PBUF_POOL_SIZE 24 26 | #define LWIP_ARP 1 27 | #define LWIP_ETHERNET 1 28 | #define LWIP_ICMP 1 29 | #define LWIP_RAW 1 30 | #define TCP_WND (8 * TCP_MSS) 31 | #define TCP_MSS 1460 32 | #define TCP_SND_BUF (8 * TCP_MSS) 33 | #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS)) 34 | #define LWIP_NETIF_STATUS_CALLBACK 1 35 | #define LWIP_NETIF_LINK_CALLBACK 1 36 | #define LWIP_NETIF_HOSTNAME 1 37 | #define LWIP_NETCONN 0 38 | #define MEM_STATS 0 39 | #define SYS_STATS 0 40 | #define MEMP_STATS 0 41 | #define LINK_STATS 0 42 | // #define ETH_PAD_SIZE 2 43 | #define LWIP_CHKSUM_ALGORITHM 3 44 | #define LWIP_DHCP 1 45 | #define LWIP_IPV4 1 46 | #define LWIP_TCP 1 47 | #define LWIP_UDP 1 48 | #define LWIP_DNS 1 49 | #define LWIP_TCP_KEEPALIVE 1 50 | #define LWIP_NETIF_TX_SINGLE_PBUF 1 51 | #define DHCP_DOES_ARP_CHECK 0 52 | #define LWIP_DHCP_DOES_ACD_CHECK 0 53 | 54 | #ifndef NDEBUG 55 | #define LWIP_DEBUG 1 56 | #define LWIP_STATS 1 57 | #define LWIP_STATS_DISPLAY 1 58 | #endif 59 | 60 | #define ETHARP_DEBUG LWIP_DBG_OFF 61 | #define NETIF_DEBUG LWIP_DBG_OFF 62 | #define PBUF_DEBUG LWIP_DBG_OFF 63 | #define API_LIB_DEBUG LWIP_DBG_OFF 64 | #define API_MSG_DEBUG LWIP_DBG_OFF 65 | #define SOCKETS_DEBUG LWIP_DBG_OFF 66 | #define ICMP_DEBUG LWIP_DBG_OFF 67 | #define INET_DEBUG LWIP_DBG_OFF 68 | #define IP_DEBUG LWIP_DBG_OFF 69 | #define IP_REASS_DEBUG LWIP_DBG_OFF 70 | #define RAW_DEBUG LWIP_DBG_OFF 71 | #define MEM_DEBUG LWIP_DBG_OFF 72 | #define MEMP_DEBUG LWIP_DBG_OFF 73 | #define SYS_DEBUG LWIP_DBG_OFF 74 | #define TCP_DEBUG LWIP_DBG_OFF 75 | #define TCP_INPUT_DEBUG LWIP_DBG_OFF 76 | #define TCP_OUTPUT_DEBUG LWIP_DBG_OFF 77 | #define TCP_RTO_DEBUG LWIP_DBG_OFF 78 | #define TCP_CWND_DEBUG LWIP_DBG_OFF 79 | #define TCP_WND_DEBUG LWIP_DBG_OFF 80 | #define TCP_FR_DEBUG LWIP_DBG_OFF 81 | #define TCP_QLEN_DEBUG LWIP_DBG_OFF 82 | #define TCP_RST_DEBUG LWIP_DBG_OFF 83 | #define UDP_DEBUG LWIP_DBG_OFF 84 | #define TCPIP_DEBUG LWIP_DBG_OFF 85 | #define PPP_DEBUG LWIP_DBG_OFF 86 | #define SLIP_DEBUG LWIP_DBG_OFF 87 | #define DHCP_DEBUG LWIP_DBG_OFF 88 | 89 | #endif /* __LWIPOPTS_H__ */ 90 | --------------------------------------------------------------------------------