├── cmake ├── CMakeLists.txt └── build_variants │ ├── other.h │ ├── main.c │ ├── other.c │ └── CMakeLists.txt ├── pio ├── squarewave │ ├── generated │ │ ├── squarewave.hex │ │ ├── squarewave.pio.h │ │ └── squarewave_wrap.pio.h │ ├── squarewave.pio │ ├── squarewave_fast.pio │ ├── squarewave_wrap.pio │ └── CMakeLists.txt ├── hub75 │ ├── mountains_128x64.png │ ├── CMakeLists.txt │ └── Readme.md ├── ir_nec │ ├── pio_ir_loopback.fzz │ ├── pio_ir_loopback.png │ ├── CMakeLists.txt │ ├── nec_transmit_library │ │ ├── nec_transmit.h │ │ ├── CMakeLists.txt │ │ └── nec_carrier_burst.pio │ ├── nec_receive_library │ │ ├── nec_receive.h │ │ └── CMakeLists.txt │ └── ir_loopback │ │ └── CMakeLists.txt ├── st7789_lcd │ ├── raspberry_256x256.png │ ├── CMakeLists.txt │ └── st7789_lcd.pio ├── pwm │ ├── CMakeLists.txt │ ├── pwm.pio │ └── pwm.c ├── logic_analyser │ └── CMakeLists.txt ├── uart_tx │ ├── CMakeLists.txt │ ├── uart_tx.c │ └── uart_tx.pio ├── addition │ ├── CMakeLists.txt │ ├── addition.pio │ └── addition.c ├── hello_pio │ ├── CMakeLists.txt │ ├── hello.pio │ └── hello.c ├── apa102 │ ├── CMakeLists.txt │ └── apa102.c ├── uart_rx │ ├── CMakeLists.txt │ └── uart_rx.c ├── manchester_encoding │ ├── CMakeLists.txt │ └── manchester_encoding.c ├── i2c │ ├── CMakeLists.txt │ ├── pio_i2c.h │ └── i2c_bus_scan.c ├── clocked_input │ ├── CMakeLists.txt │ └── clocked_input.pio ├── differential_manchester │ ├── CMakeLists.txt │ └── differential_manchester.c ├── quadrature_encoder │ └── CMakeLists.txt ├── pio_blink │ ├── CMakeLists.txt │ ├── blink.pio │ └── blink.c ├── spi │ ├── pio_spi.h │ └── CMakeLists.txt ├── CMakeLists.txt └── ws2812 │ ├── generated │ └── ws2812.py │ └── CMakeLists.txt ├── hello_world ├── CMakeLists.txt ├── serial │ ├── CMakeLists.txt │ └── hello_serial.c └── usb │ ├── hello_usb.c │ └── CMakeLists.txt ├── .gitignore ├── interp ├── CMakeLists.txt └── hello_interp │ └── CMakeLists.txt ├── spi ├── spi_master_slave │ ├── CMakeLists.txt │ ├── spi_master_slave.fzz │ ├── spi_master_slave_bb.png │ ├── spi_master_slave_logic.png │ ├── spi_slave │ │ └── CMakeLists.txt │ └── spi_master │ │ └── CMakeLists.txt ├── bme280_spi │ ├── bme280_spi.fzz │ ├── bme280_spi_bb.png │ ├── CMakeLists.txt │ └── README.adoc ├── mpu9250_spi │ ├── mpu9250_spi.fzz │ ├── mpu9250_spi_bb.png │ ├── CMakeLists.txt │ └── README.adoc ├── spi_dma │ └── CMakeLists.txt ├── CMakeLists.txt ├── spi_flash │ └── CMakeLists.txt ├── max7219_32x8_spi │ ├── CMakeLists.txt │ └── README.adoc └── max7219_8x7seg_spi │ ├── CMakeLists.txt │ └── README.adoc ├── watchdog ├── CMakeLists.txt └── hello_watchdog │ ├── CMakeLists.txt │ └── hello_watchdog.c ├── i2c ├── oled_i2c │ ├── oled_i2c.fzz │ ├── oled_i2c_bb.png │ ├── raspberry26x32.bmp │ ├── CMakeLists.txt │ └── raspberry26x32.h ├── bmp280_i2c │ ├── bmp280_i2c.fzz │ ├── bmp280_i2c_bb.png │ └── CMakeLists.txt ├── lis3dh_i2c │ ├── lis3dh_i2c.fzz │ ├── lis3dh_i2c.png │ ├── CMakeLists.txt │ └── README.adoc ├── pcf8523_i2c │ ├── pc8523_i2c.fzz │ ├── pc8523_i2c.png │ ├── CMakeLists.txt │ └── README.adoc ├── mcp9808_i2c │ ├── mcp9808_i2c.fzz │ ├── mcp9808_i2c.png │ ├── CMakeLists.txt │ └── README.adoc ├── mma8451_i2c │ ├── mma8451_i2c.fzz │ ├── mma8451_i2c.png │ ├── CMakeLists.txt │ └── README.adoc ├── mpu6050_i2c │ ├── mpu6050_i2c.fzz │ ├── mpu6050_i2c_bb.png │ ├── CMakeLists.txt │ └── README.adoc ├── pa1010d_i2c │ ├── pa1010d_i2c.fzz │ ├── pa1010d_i2c.png │ ├── CMakeLists.txt │ └── README.adoc ├── lcd_1602_i2c │ ├── lcd_1602_i2c.fzz │ ├── lcd_1602_i2c_bb.png │ ├── CMakeLists.txt │ └── README.adoc ├── mpl3115a2_i2c │ ├── mpl3115a2_i2c.fzz │ ├── mpl3115a2_i2c_bb.png │ └── CMakeLists.txt ├── bus_scan │ └── CMakeLists.txt └── CMakeLists.txt ├── uart ├── lcd_uart │ ├── lcd_uart.fzz │ ├── lcd_uart_bb.png │ └── CMakeLists.txt ├── CMakeLists.txt ├── hello_uart │ ├── CMakeLists.txt │ └── hello_uart.c └── uart_advanced │ └── CMakeLists.txt ├── usb ├── README.md ├── device │ ├── dev_hid_composite │ │ ├── README.md │ │ ├── CMakeLists.txt │ │ ├── LICENSE.TXT │ │ └── usb_descriptors.h │ ├── CMakeLists.txt │ └── dev_lowlevel │ │ ├── CMakeLists.txt │ │ └── dev_lowlevel_loopback.py ├── host │ ├── CMakeLists.txt │ └── host_cdc_msc_hid │ │ ├── CMakeLists.txt │ │ └── LICENSE.TXT └── CMakeLists.txt ├── gpio ├── dht_sensor │ ├── serial-output.png │ ├── pi-and-pico-uart-and-dht-sensor.fzz │ ├── pi-and-pico-uart-and-dht-sensor.png │ └── CMakeLists.txt ├── hello_7segment │ ├── hello_7segment.fzz │ ├── hello_7segment_bb.png │ ├── CMakeLists.txt │ └── README.adoc ├── CMakeLists.txt └── hello_gpio_irq │ ├── CMakeLists.txt │ └── hello_gpio_irq.c ├── picoboard ├── CMakeLists.txt ├── blinky │ ├── CMakeLists.txt │ └── blinky.c └── button │ └── CMakeLists.txt ├── adc ├── microphone_adc │ ├── microphone_adc.fzz │ ├── microphone_adc_bb.png │ ├── microphone_adc_plotter.png │ ├── CMakeLists.txt │ └── microphone_adc.c ├── CMakeLists.txt ├── hello_adc │ ├── CMakeLists.txt │ └── hello_adc.c ├── adc_console │ └── CMakeLists.txt ├── joystick_display │ ├── CMakeLists.txt │ └── joystick_display.c ├── onboard_temperature │ ├── CMakeLists.txt │ └── onboard_temperature.c └── dma_capture │ ├── CMakeLists.txt │ └── resistor_dac.pio ├── dma ├── CMakeLists.txt ├── hello_dma │ ├── CMakeLists.txt │ └── hello_dma.c ├── control_blocks │ └── CMakeLists.txt └── channel_irq │ ├── CMakeLists.txt │ └── pio_serialiser.pio ├── pwm ├── CMakeLists.txt ├── hello_pwm │ ├── CMakeLists.txt │ └── hello_pwm.c ├── led_fade │ └── CMakeLists.txt └── measure_duty_cycle │ └── CMakeLists.txt ├── rtc ├── CMakeLists.txt ├── hello_rtc │ ├── CMakeLists.txt │ └── hello_rtc.c ├── rtc_alarm │ ├── CMakeLists.txt │ └── rtc_alarm.c └── rtc_alarm_repeat │ ├── CMakeLists.txt │ └── rtc_alarm_repeat.c ├── timer ├── CMakeLists.txt ├── hello_timer │ ├── CMakeLists.txt │ └── hello_timer.c ├── periodic_sampler │ └── CMakeLists.txt └── timer_lowlevel │ ├── CMakeLists.txt │ └── timer_lowlevel.c ├── system ├── CMakeLists.txt ├── narrow_io_write │ └── CMakeLists.txt ├── unique_board_id │ ├── CMakeLists.txt │ └── unique_board_id.c └── hello_double_tap │ ├── CMakeLists.txt │ └── hello_double_tap.c ├── clocks ├── CMakeLists.txt ├── hello_gpout │ ├── CMakeLists.txt │ └── hello_gpout.c ├── hello_resus │ ├── CMakeLists.txt │ └── hello_resus.c ├── hello_48MHz │ └── CMakeLists.txt └── detached_clk_peri │ └── CMakeLists.txt ├── flash ├── CMakeLists.txt ├── ssi_dma │ └── CMakeLists.txt ├── program │ ├── CMakeLists.txt │ └── flash_program.c ├── cache_perfctr │ └── CMakeLists.txt ├── xip_stream │ └── CMakeLists.txt └── nuke │ ├── CMakeLists.txt │ └── nuke.c ├── multicore ├── CMakeLists.txt ├── multicore_runner │ └── CMakeLists.txt ├── multicore_fifo_irqs │ ├── CMakeLists.txt │ └── multicore_fifo_irqs.c ├── multicore_runner_queue │ └── CMakeLists.txt └── hello_multicore │ ├── CMakeLists.txt │ └── multicore.c ├── blink ├── CMakeLists.txt └── blink.c ├── pico_w ├── freertos │ ├── CMakeLists.txt │ ├── iperf │ │ ├── lwipopts.h │ │ └── CMakeLists.txt │ └── ping │ │ ├── lwipopts.h │ │ └── CMakeLists.txt ├── iperf │ ├── lwipopts.h │ └── CMakeLists.txt ├── ntp_client │ ├── lwipopts.h │ └── CMakeLists.txt ├── tcp_client │ ├── lwipopts.h │ └── CMakeLists.txt ├── tcp_server │ ├── lwipopts.h │ └── CMakeLists.txt ├── wifi_scan │ ├── lwipopts.h │ └── CMakeLists.txt ├── access_point │ ├── lwipopts.h │ ├── CMakeLists.txt │ └── dhcpserver │ │ ├── LICENSE │ │ └── dhcpserver.h ├── blink │ ├── CMakeLists.txt │ └── picow_blink.c ├── CMakeLists.txt └── python_test_tcp │ └── python_test_tcp_client.py ├── example_auto_set_url.cmake ├── divider └── CMakeLists.txt ├── reset ├── CMakeLists.txt └── hello_reset │ ├── CMakeLists.txt │ └── hello_reset.c ├── ide └── vscode │ ├── settings.json │ ├── launch-remote-openocd.json │ └── launch-raspberrypi-swd.json ├── LICENSE.TXT ├── CMakeLists.txt └── CONTRIBUTING.md /cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(build_variants) -------------------------------------------------------------------------------- /pio/squarewave/generated/squarewave.hex: -------------------------------------------------------------------------------- 1 | e081 2 | e101 3 | e000 4 | 0001 5 | -------------------------------------------------------------------------------- /hello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(serial) 2 | add_subdirectory(usb) 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | _deps 4 | cmake-* 5 | build 6 | .DS_Store 7 | *.pdf 8 | -------------------------------------------------------------------------------- /interp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_interp) 3 | endif () 4 | -------------------------------------------------------------------------------- /spi/spi_master_slave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(spi_master) 2 | add_subdirectory(spi_slave) 3 | -------------------------------------------------------------------------------- /watchdog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_watchdog) 3 | endif () 4 | -------------------------------------------------------------------------------- /i2c/oled_i2c/oled_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/oled_i2c/oled_i2c.fzz -------------------------------------------------------------------------------- /uart/lcd_uart/lcd_uart.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/uart/lcd_uart/lcd_uart.fzz -------------------------------------------------------------------------------- /usb/README.md: -------------------------------------------------------------------------------- 1 | Note: most of these examples are copies of the tinyusb examples in pico-sdk/lib/tinyusb/examples 2 | -------------------------------------------------------------------------------- /i2c/bmp280_i2c/bmp280_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/bmp280_i2c/bmp280_i2c.fzz -------------------------------------------------------------------------------- /i2c/lis3dh_i2c/lis3dh_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/lis3dh_i2c/lis3dh_i2c.fzz -------------------------------------------------------------------------------- /i2c/lis3dh_i2c/lis3dh_i2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/lis3dh_i2c/lis3dh_i2c.png -------------------------------------------------------------------------------- /i2c/oled_i2c/oled_i2c_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/oled_i2c/oled_i2c_bb.png -------------------------------------------------------------------------------- /i2c/pcf8523_i2c/pc8523_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/pcf8523_i2c/pc8523_i2c.fzz -------------------------------------------------------------------------------- /i2c/pcf8523_i2c/pc8523_i2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/pcf8523_i2c/pc8523_i2c.png -------------------------------------------------------------------------------- /pio/hub75/mountains_128x64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/pio/hub75/mountains_128x64.png -------------------------------------------------------------------------------- /pio/ir_nec/pio_ir_loopback.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/pio/ir_nec/pio_ir_loopback.fzz -------------------------------------------------------------------------------- /pio/ir_nec/pio_ir_loopback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/pio/ir_nec/pio_ir_loopback.png -------------------------------------------------------------------------------- /spi/bme280_spi/bme280_spi.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/bme280_spi/bme280_spi.fzz -------------------------------------------------------------------------------- /uart/lcd_uart/lcd_uart_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/uart/lcd_uart/lcd_uart_bb.png -------------------------------------------------------------------------------- /i2c/bmp280_i2c/bmp280_i2c_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/bmp280_i2c/bmp280_i2c_bb.png -------------------------------------------------------------------------------- /i2c/mcp9808_i2c/mcp9808_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mcp9808_i2c/mcp9808_i2c.fzz -------------------------------------------------------------------------------- /i2c/mcp9808_i2c/mcp9808_i2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mcp9808_i2c/mcp9808_i2c.png -------------------------------------------------------------------------------- /i2c/mma8451_i2c/mma8451_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mma8451_i2c/mma8451_i2c.fzz -------------------------------------------------------------------------------- /i2c/mma8451_i2c/mma8451_i2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mma8451_i2c/mma8451_i2c.png -------------------------------------------------------------------------------- /i2c/mpu6050_i2c/mpu6050_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mpu6050_i2c/mpu6050_i2c.fzz -------------------------------------------------------------------------------- /i2c/oled_i2c/raspberry26x32.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/oled_i2c/raspberry26x32.bmp -------------------------------------------------------------------------------- /i2c/pa1010d_i2c/pa1010d_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/pa1010d_i2c/pa1010d_i2c.fzz -------------------------------------------------------------------------------- /i2c/pa1010d_i2c/pa1010d_i2c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/pa1010d_i2c/pa1010d_i2c.png -------------------------------------------------------------------------------- /spi/bme280_spi/bme280_spi_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/bme280_spi/bme280_spi_bb.png -------------------------------------------------------------------------------- /spi/mpu9250_spi/mpu9250_spi.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/mpu9250_spi/mpu9250_spi.fzz -------------------------------------------------------------------------------- /gpio/dht_sensor/serial-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/gpio/dht_sensor/serial-output.png -------------------------------------------------------------------------------- /i2c/lcd_1602_i2c/lcd_1602_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/lcd_1602_i2c/lcd_1602_i2c.fzz -------------------------------------------------------------------------------- /i2c/mpl3115a2_i2c/mpl3115a2_i2c.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mpl3115a2_i2c/mpl3115a2_i2c.fzz -------------------------------------------------------------------------------- /i2c/mpu6050_i2c/mpu6050_i2c_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mpu6050_i2c/mpu6050_i2c_bb.png -------------------------------------------------------------------------------- /picoboard/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(blinky) 3 | add_subdirectory(button) 4 | endif () 5 | -------------------------------------------------------------------------------- /spi/mpu9250_spi/mpu9250_spi_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/mpu9250_spi/mpu9250_spi_bb.png -------------------------------------------------------------------------------- /adc/microphone_adc/microphone_adc.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/adc/microphone_adc/microphone_adc.fzz -------------------------------------------------------------------------------- /i2c/lcd_1602_i2c/lcd_1602_i2c_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/lcd_1602_i2c/lcd_1602_i2c_bb.png -------------------------------------------------------------------------------- /pio/st7789_lcd/raspberry_256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/pio/st7789_lcd/raspberry_256x256.png -------------------------------------------------------------------------------- /adc/microphone_adc/microphone_adc_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/adc/microphone_adc/microphone_adc_bb.png -------------------------------------------------------------------------------- /gpio/hello_7segment/hello_7segment.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/gpio/hello_7segment/hello_7segment.fzz -------------------------------------------------------------------------------- /i2c/mpl3115a2_i2c/mpl3115a2_i2c_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/i2c/mpl3115a2_i2c/mpl3115a2_i2c_bb.png -------------------------------------------------------------------------------- /gpio/hello_7segment/hello_7segment_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/gpio/hello_7segment/hello_7segment_bb.png -------------------------------------------------------------------------------- /spi/spi_master_slave/spi_master_slave.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/spi_master_slave/spi_master_slave.fzz -------------------------------------------------------------------------------- /adc/microphone_adc/microphone_adc_plotter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/adc/microphone_adc/microphone_adc_plotter.png -------------------------------------------------------------------------------- /spi/spi_master_slave/spi_master_slave_bb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/spi_master_slave/spi_master_slave_bb.png -------------------------------------------------------------------------------- /spi/spi_master_slave/spi_master_slave_logic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/spi/spi_master_slave/spi_master_slave_logic.png -------------------------------------------------------------------------------- /gpio/dht_sensor/pi-and-pico-uart-and-dht-sensor.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/gpio/dht_sensor/pi-and-pico-uart-and-dht-sensor.fzz -------------------------------------------------------------------------------- /gpio/dht_sensor/pi-and-pico-uart-and-dht-sensor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/peterharperuk/pico-examples/HEAD/gpio/dht_sensor/pi-and-pico-uart-and-dht-sensor.png -------------------------------------------------------------------------------- /cmake/build_variants/other.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | void do_other(); -------------------------------------------------------------------------------- /dma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(channel_irq) 3 | add_subdirectory(control_blocks) 4 | add_subdirectory(hello_dma) 5 | endif () 6 | -------------------------------------------------------------------------------- /pwm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_pwm) 3 | add_subdirectory(led_fade) 4 | add_subdirectory(measure_duty_cycle) 5 | endif () 6 | -------------------------------------------------------------------------------- /rtc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_rtc) 3 | add_subdirectory(rtc_alarm) 4 | add_subdirectory(rtc_alarm_repeat) 5 | endif () 6 | -------------------------------------------------------------------------------- /timer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_timer) 3 | endif () 4 | add_subdirectory(periodic_sampler) 5 | add_subdirectory(timer_lowlevel) 6 | -------------------------------------------------------------------------------- /uart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_uart) 3 | add_subdirectory(lcd_uart) 4 | add_subdirectory(uart_advanced) 5 | endif () 6 | -------------------------------------------------------------------------------- /gpio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(dht_sensor) 3 | add_subdirectory(hello_7segment) 4 | add_subdirectory(hello_gpio_irq) 5 | endif () 6 | -------------------------------------------------------------------------------- /system/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_double_tap) 3 | add_subdirectory(narrow_io_write) 4 | add_subdirectory(unique_board_id) 5 | endif () 6 | -------------------------------------------------------------------------------- /clocks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(detached_clk_peri) 3 | add_subdirectory(hello_48MHz) 4 | add_subdirectory(hello_gpout) 5 | add_subdirectory(hello_resus) 6 | endif () 7 | -------------------------------------------------------------------------------- /flash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(cache_perfctr) 3 | add_subdirectory(nuke) 4 | add_subdirectory(program) 5 | add_subdirectory(ssi_dma) 6 | add_subdirectory(xip_stream) 7 | endif () 8 | -------------------------------------------------------------------------------- /pio/ir_nec/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # build the transmit and receive libraries 2 | # 3 | add_subdirectory(nec_transmit_library) 4 | add_subdirectory(nec_receive_library) 5 | 6 | # build the example program 7 | # 8 | add_subdirectory(ir_loopback) 9 | -------------------------------------------------------------------------------- /multicore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(hello_multicore) 3 | add_subdirectory(multicore_fifo_irqs) 4 | add_subdirectory(multicore_runner) 5 | add_subdirectory(multicore_runner_queue) 6 | endif () 7 | -------------------------------------------------------------------------------- /usb/device/dev_hid_composite/README.md: -------------------------------------------------------------------------------- 1 | This is a copy of the hid_composite example from TinyUSB (https://github.com/hathach/tinyusb/tree/master/examples/device/hid_composite) 2 | showing how to build with TinyUSB when using the Raspberry Pi Pico SDK -------------------------------------------------------------------------------- /usb/host/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FAMILY rp2040) 2 | set(BOARD pico_sdk) 3 | set(TINYUSB_FAMILY_PROJECT_NAME_PREFIX "tinyusb_host_") 4 | add_subdirectory(${PICO_TINYUSB_PATH}/examples/host tinyusb_host_examples) 5 | 6 | add_subdirectory(host_cdc_msc_hid) -------------------------------------------------------------------------------- /gpio/dht_sensor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(dht 2 | dht.c 3 | ) 4 | 5 | target_link_libraries(dht pico_stdlib) 6 | 7 | pico_add_extra_outputs(dht) 8 | 9 | # add url via pico_set_program_url 10 | example_auto_set_url(dht) 11 | 12 | -------------------------------------------------------------------------------- /usb/device/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FAMILY rp2040) 2 | set(BOARD pico_sdk) 3 | set(TINYUSB_FAMILY_PROJECT_NAME_PREFIX "tinyusb_dev_") 4 | add_subdirectory(${PICO_TINYUSB_PATH}/examples/device tinyusb_device_examples) 5 | 6 | add_subdirectory(dev_hid_composite) 7 | add_subdirectory(dev_lowlevel) 8 | -------------------------------------------------------------------------------- /adc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(adc_console) 3 | add_subdirectory(dma_capture) 4 | add_subdirectory(hello_adc) 5 | add_subdirectory(joystick_display) 6 | add_subdirectory(onboard_temperature) 7 | add_subdirectory(microphone_adc) 8 | endif () 9 | -------------------------------------------------------------------------------- /blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(blink 2 | blink.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(blink pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(blink) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(blink) 13 | -------------------------------------------------------------------------------- /pico_w/freertos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT FREERTOS_KERNEL_PATH AND NOT DEFINED ENV{FREERTOS_KERNEL_PATH}) 2 | message("Skipping Pico W FreeRTOS examples as FREERTOS_KERNEL_PATH not defined") 3 | else() 4 | include(FreeRTOS_Kernel_import.cmake) 5 | 6 | add_subdirectory(iperf) 7 | add_subdirectory(ping) 8 | endif() -------------------------------------------------------------------------------- /adc/hello_adc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_adc 2 | hello_adc.c 3 | ) 4 | 5 | target_link_libraries(hello_adc pico_stdlib hardware_adc) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(hello_adc) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(hello_adc) 12 | -------------------------------------------------------------------------------- /dma/hello_dma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_dma 2 | hello_dma.c 3 | ) 4 | 5 | target_link_libraries(hello_dma pico_stdlib hardware_dma) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(hello_dma) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(hello_dma) 12 | -------------------------------------------------------------------------------- /spi/spi_dma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(spi_dma 2 | spi_dma.c 3 | ) 4 | 5 | target_link_libraries(spi_dma pico_stdlib hardware_spi hardware_dma) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(spi_dma) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(spi_dma) 12 | -------------------------------------------------------------------------------- /example_auto_set_url.cmake: -------------------------------------------------------------------------------- 1 | set(PICO_EXAMPLE_URL_BASE "https://github.com/raspberrypi/pico-examples/tree/HEAD") 2 | macro(example_auto_set_url TARGET) 3 | file(RELATIVE_PATH URL_REL_PATH "${PICO_EXAMPLES_PATH}" "${CMAKE_CURRENT_LIST_DIR}") 4 | pico_set_program_url(${TARGET} "${PICO_EXAMPLE_URL_BASE}/${URL_REL_PATH}") 5 | endmacro() -------------------------------------------------------------------------------- /usb/device/dev_lowlevel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(dev_lowlevel 2 | dev_lowlevel.c 3 | ) 4 | 5 | target_link_libraries(dev_lowlevel PRIVATE pico_stdlib hardware_resets hardware_irq) 6 | pico_add_extra_outputs(dev_lowlevel) 7 | 8 | # add url via pico_set_program_url 9 | example_auto_set_url(dev_lowlevel) 10 | -------------------------------------------------------------------------------- /spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(bme280_spi) 3 | add_subdirectory(mpu9250_spi) 4 | add_subdirectory(spi_dma) 5 | add_subdirectory(spi_master_slave) 6 | add_subdirectory(spi_flash) 7 | add_subdirectory(max7219_32x8_spi) 8 | add_subdirectory(max7219_8x7seg_spi) 9 | endif () 10 | -------------------------------------------------------------------------------- /adc/adc_console/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(adc_console 2 | adc_console.c 3 | ) 4 | 5 | target_link_libraries(adc_console pico_stdlib hardware_adc) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(adc_console) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(adc_console) 12 | 13 | -------------------------------------------------------------------------------- /usb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (TARGET tinyusb_device) 2 | add_subdirectory(device) 3 | else () 4 | message("Skipping TinyUSB device examples as TinyUSB is unavailable") 5 | endif () 6 | if (TARGET tinyusb_host) 7 | add_subdirectory(host) 8 | else () 9 | message("Skipping TinyUSB host examples as TinyUSB is unavailable") 10 | endif () -------------------------------------------------------------------------------- /pico_w/iperf/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pio/ir_nec/nec_transmit_library/nec_transmit.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 mjcross 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | #include "hardware/pio.h" 9 | 10 | // public API 11 | 12 | int nec_tx_init(PIO pio, uint pin); 13 | uint32_t nec_encode_frame(uint8_t address, uint8_t data); 14 | -------------------------------------------------------------------------------- /watchdog/hello_watchdog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_watchdog 2 | hello_watchdog.c 3 | ) 4 | 5 | target_link_libraries(hello_watchdog pico_stdlib) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(hello_watchdog) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(hello_watchdog) 12 | -------------------------------------------------------------------------------- /pico_w/ntp_client/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pico_w/tcp_client/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pico_w/tcp_server/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pico_w/wifi_scan/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /uart/hello_uart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_uart 2 | hello_uart.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_uart pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_uart) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_uart) 13 | -------------------------------------------------------------------------------- /divider/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_divider 2 | hello_divider.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_divider pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_divider) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_divider) 13 | -------------------------------------------------------------------------------- /pico_w/access_point/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pio/pwm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_pwm) 2 | 3 | pico_generate_pio_header(pio_pwm ${CMAKE_CURRENT_LIST_DIR}/pwm.pio) 4 | 5 | target_sources(pio_pwm PRIVATE pwm.c) 6 | 7 | target_link_libraries(pio_pwm PRIVATE pico_stdlib hardware_pio) 8 | pico_add_extra_outputs(pio_pwm) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(pio_pwm) -------------------------------------------------------------------------------- /timer/hello_timer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_timer 2 | hello_timer.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_timer pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_timer) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_timer) 13 | -------------------------------------------------------------------------------- /clocks/hello_gpout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_gpout 2 | hello_gpout.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_gpout pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_gpout) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_gpout) 13 | -------------------------------------------------------------------------------- /clocks/hello_resus/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_resus 2 | hello_resus.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_resus pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_resus) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_resus) 13 | -------------------------------------------------------------------------------- /pio/ir_nec/nec_receive_library/nec_receive.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 mjcross 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | #include "hardware/pio.h" 9 | 10 | // public API 11 | 12 | int nec_rx_init(PIO pio, uint pin); 13 | bool nec_decode_frame(uint32_t sm, uint8_t *p_address, uint8_t *p_data); 14 | -------------------------------------------------------------------------------- /pio/logic_analyser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_logic_analyser) 2 | 3 | target_sources(pio_logic_analyser PRIVATE logic_analyser.c) 4 | 5 | target_link_libraries(pio_logic_analyser PRIVATE pico_stdlib hardware_pio hardware_dma) 6 | pico_add_extra_outputs(pio_logic_analyser) 7 | 8 | # add url via pico_set_program_url 9 | example_auto_set_url(pio_logic_analyser) -------------------------------------------------------------------------------- /adc/joystick_display/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(joystick_display 2 | joystick_display.c 3 | ) 4 | 5 | target_link_libraries(joystick_display pico_stdlib hardware_adc) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(joystick_display) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(joystick_display) 12 | -------------------------------------------------------------------------------- /dma/control_blocks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(dma_control_blocks 2 | control_blocks.c 3 | ) 4 | 5 | target_link_libraries(dma_control_blocks pico_stdlib hardware_dma) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(dma_control_blocks) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(dma_control_blocks) 12 | -------------------------------------------------------------------------------- /hello_world/serial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_serial 2 | hello_serial.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_serial pico_stdlib) 7 | 8 | # create map/bin/hex/uf2 file etc. 9 | pico_add_extra_outputs(hello_serial) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_serial) 13 | -------------------------------------------------------------------------------- /picoboard/blinky/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picoboard_blinky 2 | blinky.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(picoboard_blinky pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(picoboard_blinky) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(picoboard_blinky) 13 | -------------------------------------------------------------------------------- /picoboard/button/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picoboard_button 2 | button.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(picoboard_button pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(picoboard_button) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(picoboard_button) 13 | -------------------------------------------------------------------------------- /spi/spi_master_slave/spi_slave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(spi_slave 2 | spi_slave.c 3 | ) 4 | 5 | # Pull in basic dependencies 6 | target_link_libraries(spi_slave pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(spi_slave) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(spi_slave) 13 | -------------------------------------------------------------------------------- /gpio/hello_7segment/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_7segment 2 | hello_7segment.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_7segment pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_7segment) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_7segment) 13 | -------------------------------------------------------------------------------- /gpio/hello_gpio_irq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_gpio_irq 2 | hello_gpio_irq.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(hello_gpio_irq pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_gpio_irq) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_gpio_irq) 13 | -------------------------------------------------------------------------------- /flash/ssi_dma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(flash_ssi_dma 2 | flash_ssi_dma.c 3 | ) 4 | 5 | target_link_libraries(flash_ssi_dma 6 | pico_stdlib 7 | hardware_dma 8 | ) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(flash_ssi_dma) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(flash_ssi_dma) 15 | -------------------------------------------------------------------------------- /spi/spi_master_slave/spi_master/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(spi_master 2 | spi_master.c 3 | ) 4 | 5 | # Pull in basic dependencies 6 | target_link_libraries(spi_master pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(spi_master) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(spi_master) 13 | -------------------------------------------------------------------------------- /system/narrow_io_write/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(narrow_io_write 2 | narrow_io_write.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(narrow_io_write pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(narrow_io_write) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(narrow_io_write) 13 | -------------------------------------------------------------------------------- /flash/program/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(flash_program 2 | flash_program.c 3 | ) 4 | 5 | target_link_libraries(flash_program 6 | pico_stdlib 7 | hardware_flash 8 | ) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(flash_program) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(flash_program) 15 | -------------------------------------------------------------------------------- /hello_world/usb/hello_usb.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 | 10 | int main() { 11 | stdio_init_all(); 12 | while (true) { 13 | printf("Hello, world!\n"); 14 | sleep_ms(1000); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /i2c/oled_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(oled_i2c 2 | oled_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(oled_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(oled_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(oled_i2c) 13 | -------------------------------------------------------------------------------- /cmake/build_variants/main.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 "other.h" 10 | 11 | int main() { 12 | stdio_init_all(); 13 | do_other(); 14 | #ifdef DO_EXTRA 15 | printf("A little extra\n"); 16 | #endif 17 | return 0; 18 | } -------------------------------------------------------------------------------- /flash/cache_perfctr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(flash_cache_perfctr 2 | flash_cache_perfctr.c 3 | ) 4 | 5 | target_link_libraries(flash_cache_perfctr 6 | pico_stdlib 7 | ) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(flash_cache_perfctr) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(flash_cache_perfctr) 14 | -------------------------------------------------------------------------------- /hello_world/serial/hello_serial.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 | 10 | int main() { 11 | stdio_init_all(); 12 | while (true) { 13 | printf("Hello, world!\n"); 14 | sleep_ms(1000); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /multicore/multicore_runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(multicore_runner 2 | multicore_runner.c 3 | ) 4 | 5 | target_link_libraries(multicore_runner 6 | pico_multicore 7 | pico_stdlib) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(multicore_runner) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(multicore_runner) -------------------------------------------------------------------------------- /pwm/hello_pwm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_pwm 2 | hello_pwm.c 3 | ) 4 | 5 | # pull in common dependencies and additional pwm hardware support 6 | target_link_libraries(hello_pwm pico_stdlib hardware_pwm) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_pwm) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_pwm) 13 | -------------------------------------------------------------------------------- /rtc/hello_rtc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_rtc 2 | hello_rtc.c 3 | ) 4 | 5 | # pull in common dependencies and additional rtc hardware support 6 | target_link_libraries(hello_rtc pico_stdlib hardware_rtc) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_rtc) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_rtc) 13 | -------------------------------------------------------------------------------- /rtc/rtc_alarm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(rtc_alarm 2 | rtc_alarm.c 3 | ) 4 | 5 | # pull in common dependencies and additional rtc hardware support 6 | target_link_libraries(rtc_alarm pico_stdlib hardware_rtc) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(rtc_alarm) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(rtc_alarm) 13 | -------------------------------------------------------------------------------- /spi/spi_flash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(spi_flash 2 | spi_flash.c 3 | ) 4 | 5 | # pull in common dependencies and additional spi hardware support 6 | target_link_libraries(spi_flash pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(spi_flash) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(spi_flash) 13 | -------------------------------------------------------------------------------- /flash/xip_stream/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(flash_xip_stream 2 | flash_xip_stream.c 3 | ) 4 | 5 | target_link_libraries(flash_xip_stream 6 | pico_stdlib 7 | hardware_dma 8 | ) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(flash_xip_stream) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(flash_xip_stream) 15 | -------------------------------------------------------------------------------- /i2c/bmp280_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(bmp280_i2c 2 | bmp280_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(bmp280_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(bmp280_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(bmp280_i2c) 13 | -------------------------------------------------------------------------------- /i2c/bus_scan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(i2c_bus_scan 2 | bus_scan.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(i2c_bus_scan pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(i2c_bus_scan) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(i2c_bus_scan) 13 | -------------------------------------------------------------------------------- /i2c/lis3dh_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(lis3dh_i2c 2 | lis3dh_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(lis3dh_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(lis3dh_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(lis3dh_i2c) 13 | -------------------------------------------------------------------------------- /i2c/mcp9808_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mcp9808_i2c 2 | mcp9808_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(mcp9808_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(mcp9808_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(mcp9808_i2c) -------------------------------------------------------------------------------- /i2c/mma8451_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mma8451_i2c 2 | mma8451_i2c.c 3 | ) 4 | # pull in common dependencies and additional i2c hardware support 5 | target_link_libraries(mma8451_i2c pico_stdlib hardware_i2c) 6 | 7 | # create map/bin/hex file etc. 8 | pico_add_extra_outputs(mma8451_i2c) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(mma8451_i2c) 12 | -------------------------------------------------------------------------------- /pio/squarewave/squarewave.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program squarewave 8 | set pindirs, 1 ; Set pin to output 9 | again: 10 | set pins, 1 [1] ; Drive pin high and then delay for one cycle 11 | set pins, 0 ; Drive pin low 12 | jmp again ; Set PC to label `again` 13 | 14 | -------------------------------------------------------------------------------- /pio/uart_tx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_uart_tx) 2 | 3 | pico_generate_pio_header(pio_uart_tx ${CMAKE_CURRENT_LIST_DIR}/uart_tx.pio) 4 | 5 | target_sources(pio_uart_tx PRIVATE uart_tx.c) 6 | 7 | target_link_libraries(pio_uart_tx PRIVATE pico_stdlib hardware_pio) 8 | pico_add_extra_outputs(pio_uart_tx) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(pio_uart_tx) 12 | -------------------------------------------------------------------------------- /spi/bme280_spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(bme280_spi 2 | bme280_spi.c 3 | ) 4 | 5 | # pull in common dependencies and additional spi hardware support 6 | target_link_libraries(bme280_spi pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(bme280_spi) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(bme280_spi) 13 | -------------------------------------------------------------------------------- /system/unique_board_id/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(unique_board_id 2 | unique_board_id.c 3 | ) 4 | 5 | target_link_libraries(unique_board_id 6 | pico_stdlib 7 | pico_unique_id 8 | ) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(unique_board_id) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(unique_board_id) 15 | -------------------------------------------------------------------------------- /i2c/mpu6050_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mpu6050_i2c 2 | mpu6050_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(mpu6050_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(mpu6050_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(mpu6050_i2c) 13 | -------------------------------------------------------------------------------- /i2c/pa1010d_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pa1010d_i2c 2 | pa1010d_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(pa1010d_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(pa1010d_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(pa1010d_i2c) 13 | -------------------------------------------------------------------------------- /i2c/pcf8523_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pcf8523_i2c 2 | pcf8523_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(pcf8523_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(pcf8523_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(pcf8523_i2c) 13 | -------------------------------------------------------------------------------- /pio/addition/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_addition) 2 | 3 | pico_generate_pio_header(pio_addition ${CMAKE_CURRENT_LIST_DIR}/addition.pio) 4 | 5 | target_sources(pio_addition PRIVATE addition.c) 6 | 7 | target_link_libraries(pio_addition PRIVATE pico_stdlib hardware_pio) 8 | pico_add_extra_outputs(pio_addition) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(pio_addition) 12 | -------------------------------------------------------------------------------- /pwm/led_fade/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pwm_led_fade 2 | pwm_led_fade.c 3 | ) 4 | 5 | # pull in common dependencies and additional pwm hardware support 6 | target_link_libraries(pwm_led_fade pico_stdlib hardware_pwm) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(pwm_led_fade) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(pwm_led_fade) 13 | -------------------------------------------------------------------------------- /spi/mpu9250_spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mpu9250_spi 2 | mpu9250_spi.c 3 | ) 4 | 5 | # pull in common dependencies and additional spi hardware support 6 | target_link_libraries(mpu9250_spi pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(mpu9250_spi) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(mpu9250_spi) 13 | -------------------------------------------------------------------------------- /adc/microphone_adc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(microphone_adc 2 | microphone_adc.c 3 | ) 4 | 5 | # pull in common dependencies and adc hardware support 6 | target_link_libraries(microphone_adc pico_stdlib hardware_adc) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(microphone_adc) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(microphone_adc) 13 | -------------------------------------------------------------------------------- /cmake/build_variants/other.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "other.h" 9 | 10 | void do_other() { 11 | printf("The common thing is %d\n", 12 | A_DEFINE_THAT_IS_SHARED); 13 | printf("The binary local thing is %d\n", 14 | A_DEFINE_THAT_IS_NOT_SHARED); 15 | } -------------------------------------------------------------------------------- /i2c/lcd_1602_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(lcd_1602_i2c 2 | lcd_1602_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(lcd_1602_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(lcd_1602_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(lcd_1602_i2c) 13 | -------------------------------------------------------------------------------- /multicore/multicore_fifo_irqs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(multicore_fifo_irqs 2 | multicore_fifo_irqs.c 3 | ) 4 | 5 | target_link_libraries(multicore_fifo_irqs 6 | pico_multicore 7 | pico_stdlib) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(multicore_fifo_irqs) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(multicore_fifo_irqs) -------------------------------------------------------------------------------- /clocks/hello_48MHz/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_48MHz 2 | hello_48MHz.c 3 | ) 4 | 5 | # pull in common dependencies and additional clocks hardware support 6 | target_link_libraries(hello_48MHz pico_stdlib hardware_clocks) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(hello_48MHz) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(hello_48MHz) 13 | -------------------------------------------------------------------------------- /i2c/mpl3115a2_i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mpl3115a2_i2c 2 | mpl3115a2_i2c.c 3 | ) 4 | 5 | # pull in common dependencies and additional i2c hardware support 6 | target_link_libraries(mpl3115a2_i2c pico_stdlib hardware_i2c) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(mpl3115a2_i2c) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(mpl3115a2_i2c) 13 | -------------------------------------------------------------------------------- /clocks/detached_clk_peri/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(clocks_detached_clk_peri 2 | detached_clk_peri.c 3 | ) 4 | 5 | # pull in common dependencies 6 | target_link_libraries(clocks_detached_clk_peri pico_stdlib) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(clocks_detached_clk_peri) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(clocks_detached_clk_peri) 13 | -------------------------------------------------------------------------------- /uart/uart_advanced/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(uart_advanced 2 | uart_advanced.c 3 | ) 4 | 5 | # pull in common dependencies and additional uart hardware support 6 | target_link_libraries(uart_advanced pico_stdlib hardware_uart) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(uart_advanced) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(uart_advanced) 13 | -------------------------------------------------------------------------------- /multicore/multicore_runner_queue/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(multicore_runner_queue 2 | multicore_runner_queue.c 3 | ) 4 | 5 | target_link_libraries(multicore_runner_queue 6 | pico_multicore 7 | pico_stdlib) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(multicore_runner_queue) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(multicore_runner_queue) -------------------------------------------------------------------------------- /reset/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (TARGET hardware_reset) 2 | add_executable(hello_reset 3 | hello_reset.c 4 | ) 5 | 6 | # pull in common dependencies 7 | target_link_libraries(hello_reset pico_stdlib) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(hello_reset) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(hello_reset) 14 | endif () 15 | -------------------------------------------------------------------------------- /pio/hello_pio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_pio) 2 | 3 | pico_generate_pio_header(hello_pio ${CMAKE_CURRENT_LIST_DIR}/hello.pio) 4 | 5 | target_sources(hello_pio PRIVATE hello.c) 6 | 7 | target_link_libraries(hello_pio PRIVATE 8 | pico_stdlib 9 | hardware_pio 10 | ) 11 | 12 | pico_add_extra_outputs(hello_pio) 13 | 14 | # add url via pico_set_program_url 15 | example_auto_set_url(hello_pio) 16 | -------------------------------------------------------------------------------- /pio/apa102/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_apa102) 2 | 3 | pico_generate_pio_header(pio_apa102 ${CMAKE_CURRENT_LIST_DIR}/apa102.pio) 4 | 5 | target_sources(pio_apa102 PRIVATE apa102.c) 6 | 7 | target_link_libraries(pio_apa102 PRIVATE 8 | pico_stdlib 9 | hardware_pio 10 | ) 11 | 12 | pico_add_extra_outputs(pio_apa102) 13 | 14 | # add url via pico_set_program_url 15 | example_auto_set_url(pio_apa102) 16 | -------------------------------------------------------------------------------- /rtc/rtc_alarm_repeat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(rtc_alarm_repeat 2 | rtc_alarm_repeat.c 3 | ) 4 | 5 | # pull in common dependencies and additional rtc hardware support 6 | target_link_libraries(rtc_alarm_repeat pico_stdlib hardware_rtc) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(rtc_alarm_repeat) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(rtc_alarm_repeat) 13 | -------------------------------------------------------------------------------- /spi/max7219_32x8_spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(max7219_32x8_spi 2 | max7219_32x8_spi.c 3 | ) 4 | 5 | # pull in common dependencies and additional spi hardware support 6 | target_link_libraries(max7219_32x8_spi pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(max7219_32x8_spi) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(max7219_32x8_spi) 13 | -------------------------------------------------------------------------------- /pio/st7789_lcd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_st7789_lcd) 2 | 3 | pico_generate_pio_header(pio_st7789_lcd ${CMAKE_CURRENT_LIST_DIR}/st7789_lcd.pio) 4 | 5 | target_sources(pio_st7789_lcd PRIVATE st7789_lcd.c) 6 | 7 | target_link_libraries(pio_st7789_lcd PRIVATE pico_stdlib hardware_pio hardware_interp) 8 | pico_add_extra_outputs(pio_st7789_lcd) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(pio_st7789_lcd) 12 | -------------------------------------------------------------------------------- /spi/max7219_8x7seg_spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(max7219_8x7seg_spi 2 | max7219_8x7seg_spi.c 3 | ) 4 | 5 | # pull in common dependencies and additional spi hardware support 6 | target_link_libraries(max7219_8x7seg_spi pico_stdlib hardware_spi) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(max7219_8x7seg_spi) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(max7219_8x7seg_spi) 13 | -------------------------------------------------------------------------------- /multicore/hello_multicore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_multicore 2 | multicore.c 3 | ) 4 | 5 | # Add pico_multicore which is required for multicore functionality 6 | target_link_libraries(hello_multicore 7 | pico_stdlib 8 | pico_multicore) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(hello_multicore) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(hello_multicore) -------------------------------------------------------------------------------- /pio/ir_nec/ir_loopback/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable (pio_ir_loopback ir_loopback.c) 2 | 3 | # link the executable using the IR transmit and receive libraries 4 | # 5 | target_link_libraries(pio_ir_loopback LINK_PUBLIC 6 | pico_stdlib 7 | hardware_pio 8 | nec_transmit_library 9 | nec_receive_library 10 | ) 11 | 12 | pico_add_extra_outputs(pio_ir_loopback) 13 | 14 | # add url via pico_set_program_url 15 | example_auto_set_url(pio_ir_loopback) 16 | -------------------------------------------------------------------------------- /pwm/measure_duty_cycle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pwm_measure_duty_cycle 2 | measure_duty_cycle.c 3 | ) 4 | 5 | # pull in common dependencies and additional pwm hardware support 6 | target_link_libraries(pwm_measure_duty_cycle pico_stdlib hardware_pwm) 7 | 8 | # create map/bin/hex file etc. 9 | pico_add_extra_outputs(pwm_measure_duty_cycle) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(pwm_measure_duty_cycle) 13 | -------------------------------------------------------------------------------- /pio/uart_rx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_uart_rx) 2 | 3 | pico_generate_pio_header(pio_uart_rx ${CMAKE_CURRENT_LIST_DIR}/uart_rx.pio) 4 | 5 | target_sources(pio_uart_rx PRIVATE uart_rx.c) 6 | 7 | target_link_libraries(pio_uart_rx PRIVATE 8 | pico_stdlib 9 | pico_multicore 10 | hardware_pio 11 | ) 12 | 13 | pico_add_extra_outputs(pio_uart_rx) 14 | 15 | # add url via pico_set_program_url 16 | example_auto_set_url(pio_uart_rx) 17 | -------------------------------------------------------------------------------- /i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(bmp280_i2c) 3 | add_subdirectory(bus_scan) 4 | add_subdirectory(lcd_1602_i2c) 5 | add_subdirectory(lis3dh_i2c) 6 | add_subdirectory(mcp9808_i2c) 7 | add_subdirectory(mma8451_i2c) 8 | add_subdirectory(mpl3115a2_i2c) 9 | add_subdirectory(mpu6050_i2c) 10 | add_subdirectory(oled_i2c) 11 | add_subdirectory(pa1010d_i2c) 12 | add_subdirectory(pcf8523_i2c) 13 | endif () 14 | -------------------------------------------------------------------------------- /timer/periodic_sampler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_TIME_NO_ALARM_SUPPORT) 2 | add_executable(periodic_sampler 3 | periodic_sampler.c 4 | ) 5 | 6 | # pull in common dependencies 7 | target_link_libraries(periodic_sampler pico_stdlib) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(periodic_sampler) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(periodic_sampler) 14 | endif() 15 | -------------------------------------------------------------------------------- /flash/nuke/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(flash_nuke 2 | nuke.c 3 | ) 4 | 5 | target_link_libraries(flash_nuke 6 | pico_stdlib 7 | hardware_flash 8 | ) 9 | 10 | # It doesn't make sense to run this program from flash. Always build a 11 | # RAM-only binary. 12 | pico_set_binary_type(flash_nuke no_flash) 13 | 14 | pico_add_extra_outputs(flash_nuke) 15 | 16 | # add url via pico_set_program_url 17 | example_auto_set_url(flash_nuke) 18 | 19 | -------------------------------------------------------------------------------- /pico_w/blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_blink 2 | picow_blink.c 3 | ) 4 | 5 | target_link_libraries(picow_blink 6 | pico_stdlib # for core functionality 7 | pico_cyw43_arch_none # we need Wifi to access the GPIO, but we don't need anything else 8 | ) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(picow_blink) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(picow_blink) 15 | -------------------------------------------------------------------------------- /reset/hello_reset/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (TARGET hardware_resets) 2 | add_executable(hello_reset 3 | hello_reset.c 4 | ) 5 | 6 | # pull in common dependencies and additional reset hardware support 7 | target_link_libraries(hello_reset pico_stdlib hardware_resets) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(hello_reset) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(hello_reset) 14 | endif () 15 | -------------------------------------------------------------------------------- /pio/manchester_encoding/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_manchester_encoding) 2 | 3 | pico_generate_pio_header(pio_manchester_encoding ${CMAKE_CURRENT_LIST_DIR}/manchester_encoding.pio) 4 | 5 | target_sources(pio_manchester_encoding PRIVATE manchester_encoding.c) 6 | 7 | target_link_libraries(pio_manchester_encoding PRIVATE pico_stdlib hardware_pio) 8 | pico_add_extra_outputs(pio_manchester_encoding) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(pio_manchester_encoding) -------------------------------------------------------------------------------- /pio/i2c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_i2c_bus_scan) 2 | 3 | pico_generate_pio_header(pio_i2c_bus_scan ${CMAKE_CURRENT_LIST_DIR}/i2c.pio) 4 | 5 | target_sources(pio_i2c_bus_scan PRIVATE 6 | i2c_bus_scan.c 7 | pio_i2c.c 8 | pio_i2c.h 9 | ) 10 | 11 | target_link_libraries(pio_i2c_bus_scan PRIVATE pico_stdlib hardware_pio) 12 | pico_add_extra_outputs(pio_i2c_bus_scan) 13 | 14 | # add url via pico_set_program_url 15 | example_auto_set_url(pio_i2c_bus_scan) 16 | 17 | -------------------------------------------------------------------------------- /interp/hello_interp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (TARGET hardware_interp) 2 | add_executable(hello_interp 3 | hello_interp.c 4 | ) 5 | 6 | # pull in common dependencies and additional interpolator hardware support 7 | target_link_libraries(hello_interp pico_stdlib hardware_interp) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(hello_interp) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(hello_interp) 14 | endif () 15 | -------------------------------------------------------------------------------- /pio/hub75/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_hub75) 2 | 3 | pico_generate_pio_header(pio_hub75 ${CMAKE_CURRENT_LIST_DIR}/hub75.pio) 4 | 5 | target_sources(pio_hub75 PRIVATE hub75.c) 6 | 7 | target_compile_definitions(pio_hub75 PRIVATE 8 | PICO_DEFAULT_UART_TX_PIN=28 9 | PICO_DEFAULT_UART_RX_PIN=29 10 | ) 11 | 12 | target_link_libraries(pio_hub75 PRIVATE pico_stdlib hardware_pio) 13 | pico_add_extra_outputs(pio_hub75) 14 | 15 | # add url via pico_set_program_url 16 | example_auto_set_url(pio_hub75) 17 | -------------------------------------------------------------------------------- /timer/timer_lowlevel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (PICO_ON_DEVICE) 2 | add_executable(timer_lowlevel 3 | timer_lowlevel.c) 4 | 5 | # Disable SDK alarm support for this lowlevel example 6 | set(PICO_TIME_DEFAULT_ALARM_POOL_DISABLED 1) 7 | 8 | target_link_libraries(timer_lowlevel pico_stdlib) 9 | 10 | # create map/bin/hex file etc. 11 | pico_add_extra_outputs(timer_lowlevel) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(timer_lowlevel) 15 | endif () -------------------------------------------------------------------------------- /adc/onboard_temperature/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(onboard_temperature onboard_temperature.c) 2 | 3 | target_link_libraries(onboard_temperature pico_stdlib hardware_adc) 4 | 5 | # enable uart output, disable usb output 6 | pico_enable_stdio_uart(onboard_temperature 1) 7 | pico_enable_stdio_usb(onboard_temperature 0) 8 | 9 | # create map/bin/hex file etc. 10 | pico_add_extra_outputs(onboard_temperature) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(onboard_temperature) 14 | 15 | -------------------------------------------------------------------------------- /pio/clocked_input/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_clocked_input) 2 | 3 | pico_generate_pio_header(pio_clocked_input ${CMAKE_CURRENT_LIST_DIR}/clocked_input.pio) 4 | 5 | target_sources(pio_clocked_input PRIVATE clocked_input.c) 6 | 7 | target_link_libraries(pio_clocked_input PRIVATE 8 | pico_stdlib 9 | hardware_pio 10 | hardware_spi 11 | ) 12 | 13 | pico_add_extra_outputs(pio_clocked_input) 14 | 15 | # add url via pico_set_program_url 16 | example_auto_set_url(pio_clocked_input) 17 | -------------------------------------------------------------------------------- /dma/channel_irq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(dma_channel_irq 2 | channel_irq.c 3 | ) 4 | 5 | pico_generate_pio_header(dma_channel_irq ${CMAKE_CURRENT_LIST_DIR}/pio_serialiser.pio) 6 | 7 | target_link_libraries(dma_channel_irq 8 | pico_stdlib 9 | hardware_dma 10 | hardware_irq 11 | hardware_pio 12 | ) 13 | 14 | # create map/bin/hex file etc. 15 | pico_add_extra_outputs(dma_channel_irq) 16 | 17 | # add url via pico_set_program_url 18 | example_auto_set_url(dma_channel_irq) 19 | -------------------------------------------------------------------------------- /pio/differential_manchester/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_differential_manchester) 2 | 3 | pico_generate_pio_header(pio_differential_manchester ${CMAKE_CURRENT_LIST_DIR}/differential_manchester.pio) 4 | 5 | target_sources(pio_differential_manchester PRIVATE differential_manchester.c) 6 | 7 | target_link_libraries(pio_differential_manchester PRIVATE pico_stdlib hardware_pio) 8 | pico_add_extra_outputs(pio_differential_manchester) 9 | 10 | # add url via pico_set_program_url 11 | example_auto_set_url(pio_differential_manchester) -------------------------------------------------------------------------------- /uart/lcd_uart/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(lcd_uart 2 | lcd_uart.c 3 | ) 4 | 5 | # pull in common dependencies and additional uart hardware support 6 | target_link_libraries(lcd_uart pico_stdlib hardware_uart) 7 | 8 | # enable usb output and uart output 9 | # modify here as required 10 | pico_enable_stdio_usb(lcd_uart 1) 11 | pico_enable_stdio_uart(lcd_uart 1) 12 | 13 | # create map/bin/hex file etc. 14 | pico_add_extra_outputs(lcd_uart) 15 | 16 | # add url via pico_set_program_url 17 | example_auto_set_url(lcd_uart) 18 | -------------------------------------------------------------------------------- /adc/dma_capture/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(adc_dma_capture 2 | dma_capture.c 3 | ) 4 | 5 | pico_generate_pio_header(adc_dma_capture ${CMAKE_CURRENT_LIST_DIR}/resistor_dac.pio) 6 | 7 | target_link_libraries(adc_dma_capture 8 | pico_stdlib 9 | hardware_adc 10 | hardware_dma 11 | # For the dummy output: 12 | hardware_pio 13 | pico_multicore 14 | ) 15 | 16 | # create map/bin/hex file etc. 17 | pico_add_extra_outputs(adc_dma_capture) 18 | 19 | # add url via pico_set_program_url 20 | example_auto_set_url(adc_dma_capture) 21 | -------------------------------------------------------------------------------- /pico_w/blink/picow_blink.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2022 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | #include "pico/cyw43_arch.h" 9 | 10 | int main() { 11 | stdio_init_all(); 12 | if (cyw43_arch_init()) { 13 | printf("WiFi init failed"); 14 | return -1; 15 | } 16 | while (true) { 17 | cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); 18 | sleep_ms(250); 19 | cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); 20 | sleep_ms(250); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /blink/blink.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | 9 | int main() { 10 | #ifndef PICO_DEFAULT_LED_PIN 11 | #warning blink example requires a board with a regular LED 12 | #else 13 | const uint LED_PIN = PICO_DEFAULT_LED_PIN; 14 | gpio_init(LED_PIN); 15 | gpio_set_dir(LED_PIN, GPIO_OUT); 16 | while (true) { 17 | gpio_put(LED_PIN, 1); 18 | sleep_ms(250); 19 | gpio_put(LED_PIN, 0); 20 | sleep_ms(250); 21 | } 22 | #endif 23 | } 24 | -------------------------------------------------------------------------------- /pio/quadrature_encoder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_quadrature_encoder) 2 | 3 | pico_generate_pio_header(pio_quadrature_encoder ${CMAKE_CURRENT_LIST_DIR}/quadrature_encoder.pio) 4 | 5 | target_sources(pio_quadrature_encoder PRIVATE quadrature_encoder.c) 6 | 7 | target_link_libraries(pio_quadrature_encoder PRIVATE 8 | pico_stdlib 9 | pico_multicore 10 | hardware_pio 11 | ) 12 | 13 | pico_enable_stdio_usb(pio_quadrature_encoder 1) 14 | 15 | pico_add_extra_outputs(pio_quadrature_encoder) 16 | 17 | # add url via pico_set_program_url 18 | example_auto_set_url(pio_quadrature_encoder) 19 | -------------------------------------------------------------------------------- /pio/squarewave/squarewave_fast.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | ; Note that if you modify squarewave.c to include this program, you'll also 8 | ; need to set the wrap registers yourself. This would be handled for you by 9 | ; squarewave_program_get_default_config(). 10 | 11 | 12 | .program squarewave_fast 13 | ; Like squarewave_wrap, but remove the delay cycles so we can run twice as fast. 14 | set pindirs, 1 ; Set pin to output 15 | .wrap_target 16 | set pins, 1 ; Drive pin high 17 | set pins, 0 ; Drive pin low 18 | .wrap 19 | 20 | -------------------------------------------------------------------------------- /pio/ir_nec/nec_receive_library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # build a normal library 2 | # 3 | add_library(nec_receive_library nec_receive.c) 4 | 5 | # invoke pio_asm to assemble the state machine program 6 | # 7 | pico_generate_pio_header(nec_receive_library ${CMAKE_CURRENT_LIST_DIR}/nec_receive.pio) 8 | 9 | target_link_libraries(nec_receive_library PRIVATE 10 | pico_stdlib 11 | hardware_pio 12 | ) 13 | 14 | # add the `binary` directory so that the generated headers are included in the project 15 | # 16 | target_include_directories (nec_receive_library PUBLIC 17 | ${CMAKE_CURRENT_SOURCE_DIR} 18 | ${CMAKE_CURRENT_BINARY_DIR} 19 | ) 20 | -------------------------------------------------------------------------------- /pio/pio_blink/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_blink) 2 | 3 | # by default the header is generated into the build dir 4 | pico_generate_pio_header(pio_blink ${CMAKE_CURRENT_LIST_DIR}/blink.pio) 5 | # however, alternatively you can choose to generate it somewhere else (in this case in the source tree for check in) 6 | #pico_generate_pio_header(pio_blink ${CMAKE_CURRENT_LIST_DIR}/blink.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}) 7 | 8 | target_sources(pio_blink PRIVATE blink.c) 9 | 10 | target_link_libraries(pio_blink PRIVATE pico_stdlib hardware_pio) 11 | pico_add_extra_outputs(pio_blink) 12 | 13 | # add url via pico_set_program_url 14 | example_auto_set_url(pio_blink) -------------------------------------------------------------------------------- /pico_w/freertos/iperf/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #if !NO_SYS 11 | #define TCPIP_THREAD_STACKSIZE 1024 12 | #define DEFAULT_THREAD_STACKSIZE 1024 13 | #define DEFAULT_RAW_RECVMBOX_SIZE 8 14 | #define TCPIP_MBOX_SIZE 8 15 | #define LWIP_TIMEVAL_PRIVATE 0 16 | 17 | // not necessary, can be done either way 18 | #define LWIP_TCPIP_CORE_LOCKING_INPUT 1 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /pico_w/freertos/ping/lwipopts.h: -------------------------------------------------------------------------------- 1 | #ifndef _LWIPOPTS_H 2 | #define _LWIPOPTS_H 3 | 4 | // Generally you would define your own explicit list of lwIP options 5 | // (see https://www.nongnu.org/lwip/2_1_x/group__lwip__opts.html) 6 | // 7 | // This example uses a common include to avoid repetition 8 | #include "lwipopts_examples_common.h" 9 | 10 | #if !NO_SYS 11 | #define TCPIP_THREAD_STACKSIZE 1024 12 | #define DEFAULT_THREAD_STACKSIZE 1024 13 | #define DEFAULT_RAW_RECVMBOX_SIZE 8 14 | #define TCPIP_MBOX_SIZE 8 15 | #define LWIP_TIMEVAL_PRIVATE 0 16 | 17 | // not necessary, can be done either way 18 | #define LWIP_TCPIP_CORE_LOCKING_INPUT 1 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ide/vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | // These settings tweaks to the cmake plugin will ensure 3 | // that you debug using cortex-debug instead of trying to launch 4 | // a Pico binary on the host 5 | "cmake.statusbar.advanced": { 6 | "debug": { 7 | "visibility": "hidden" 8 | }, 9 | "launch": { 10 | "visibility": "hidden" 11 | }, 12 | "build": { 13 | "visibility": "hidden" 14 | }, 15 | "buildTarget": { 16 | "visibility": "hidden" 17 | } 18 | }, 19 | "cmake.buildBeforeRun": true, 20 | "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools" 21 | } -------------------------------------------------------------------------------- /pio/spi/pio_spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | #ifndef _PIO_SPI_H 7 | #define _PIO_SPI_H 8 | 9 | #include "hardware/pio.h" 10 | #include "spi.pio.h" 11 | 12 | typedef struct pio_spi_inst { 13 | PIO pio; 14 | uint sm; 15 | uint cs_pin; 16 | } pio_spi_inst_t; 17 | 18 | void pio_spi_write8_blocking(const pio_spi_inst_t *spi, const uint8_t *src, size_t len); 19 | 20 | void pio_spi_read8_blocking(const pio_spi_inst_t *spi, uint8_t *dst, size_t len); 21 | 22 | void pio_spi_write8_read8_blocking(const pio_spi_inst_t *spi, uint8_t *src, uint8_t *dst, size_t len); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /hello_world/usb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (TARGET tinyusb_device) 2 | add_executable(hello_usb 3 | hello_usb.c 4 | ) 5 | 6 | # pull in common dependencies 7 | target_link_libraries(hello_usb pico_stdlib) 8 | 9 | # enable usb output, disable uart output 10 | pico_enable_stdio_usb(hello_usb 1) 11 | pico_enable_stdio_uart(hello_usb 0) 12 | 13 | # create map/bin/hex/uf2 file etc. 14 | pico_add_extra_outputs(hello_usb) 15 | 16 | # add url via pico_set_program_url 17 | example_auto_set_url(hello_usb) 18 | elseif(PICO_ON_DEVICE) 19 | message(WARNING "not building hello_usb because TinyUSB submodule is not initialized in the SDK") 20 | endif() 21 | -------------------------------------------------------------------------------- /i2c/oled_i2c/raspberry26x32.h: -------------------------------------------------------------------------------- 1 | #define IMG_WIDTH 26 2 | #define IMG_HEIGHT 32 3 | 4 | static uint8_t raspberry26x32[] = { 0x0, 0x0, 0xe, 0x7e, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfc, 0xf8, 0xfc, 0xfe, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7e, 0x1e, 0x0, 0x0, 0x0, 0x80, 0xe0, 0xf8, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xf8, 0xe0, 0x80, 0x0, 0x0, 0x1e, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x1e, 0x0, 0x0, 0x0, 0x3, 0x7, 0xf, 0x1f, 0x1f, 0x3f, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0x3f, 0x3f, 0x1f, 0x1f, 0xf, 0x7, 0x3, 0x0, 0x0}; 5 | -------------------------------------------------------------------------------- /clocks/hello_gpout/hello_gpout.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "pico/stdlib.h" 9 | #include "hardware/clocks.h" 10 | 11 | 12 | int main() { 13 | stdio_init_all(); 14 | printf("Hello gpout\n"); 15 | 16 | // Output clk_sys / 10 to gpio 21, etc... 17 | clock_gpio_init(21, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_SYS, 10); 18 | clock_gpio_init(23, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_USB, 10); 19 | clock_gpio_init(24, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_ADC, 10); 20 | clock_gpio_init(26, CLOCKS_CLK_GPOUT0_CTRL_AUXSRC_VALUE_CLK_RTC, 10); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /system/hello_double_tap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello_double_tap 2 | hello_double_tap.c 3 | ) 4 | 5 | # Double tap reset into bootrom is injected by linking with the 6 | # pico_bootsel_via_double_reset library 7 | target_link_libraries(hello_double_tap 8 | pico_stdlib 9 | pico_bootsel_via_double_reset 10 | ) 11 | 12 | # Entering the bootloader in this way also lets us specify a GPIO to be used 13 | # as a bootloader activity LED: 14 | target_compile_definitions(hello_double_tap PRIVATE 15 | PICO_BOOTSEL_VIA_DOUBLE_RESET_ACTIVITY_LED=25 16 | ) 17 | 18 | pico_add_extra_outputs(hello_double_tap) 19 | 20 | # add url via pico_set_program_url 21 | example_auto_set_url(hello_double_tap) 22 | -------------------------------------------------------------------------------- /pio/squarewave/squarewave_wrap.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | ; Note that if you modify squarewave.c to include this program, you'll also 8 | ; need to set the wrap registers yourself. This would be handled for you by 9 | ; squarewave_program_get_default_config(). 10 | 11 | .program squarewave_wrap 12 | ; Like squarewave, but use the state machine's .wrap hardware instead of an 13 | ; explicit jmp. This is a free (0-cycle) unconditional jump. 14 | 15 | set pindirs, 1 ; Set pin to output 16 | .wrap_target 17 | set pins, 1 [1] ; Drive pin high and then delay for one cycle 18 | set pins, 0 [1] ; Drive pin low and then delay for one cycle 19 | .wrap 20 | -------------------------------------------------------------------------------- /pio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT PICO_NO_HARDWARE) 2 | add_subdirectory(addition) 3 | add_subdirectory(apa102) 4 | add_subdirectory(clocked_input) 5 | add_subdirectory(differential_manchester) 6 | add_subdirectory(hello_pio) 7 | add_subdirectory(hub75) 8 | add_subdirectory(i2c) 9 | add_subdirectory(ir_nec) 10 | add_subdirectory(logic_analyser) 11 | add_subdirectory(manchester_encoding) 12 | add_subdirectory(pio_blink) 13 | add_subdirectory(pwm) 14 | add_subdirectory(quadrature_encoder) 15 | add_subdirectory(spi) 16 | add_subdirectory(squarewave) 17 | add_subdirectory(st7789_lcd) 18 | add_subdirectory(uart_rx) 19 | add_subdirectory(uart_tx) 20 | add_subdirectory(ws2812) 21 | endif () 22 | -------------------------------------------------------------------------------- /pio/ir_nec/nec_transmit_library/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # build a normal library 2 | # 3 | add_library(nec_transmit_library nec_transmit.c) 4 | 5 | # invoke pio_asm to assemble the PIO state machine programs 6 | # 7 | pico_generate_pio_header(nec_transmit_library ${CMAKE_CURRENT_LIST_DIR}/nec_carrier_burst.pio) 8 | pico_generate_pio_header(nec_transmit_library ${CMAKE_CURRENT_LIST_DIR}/nec_carrier_control.pio) 9 | 10 | target_link_libraries(nec_transmit_library PRIVATE 11 | pico_stdlib 12 | hardware_pio 13 | ) 14 | 15 | # add the `binary` directory so that the generated headers are included in the project 16 | # 17 | target_include_directories (nec_transmit_library PUBLIC 18 | ${CMAKE_CURRENT_SOURCE_DIR} 19 | ${CMAKE_CURRENT_BINARY_DIR} 20 | ) 21 | -------------------------------------------------------------------------------- /reset/hello_reset/hello_reset.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/resets.h" 10 | 11 | /// \tag::hello_reset[] 12 | int main() { 13 | stdio_init_all(); 14 | 15 | printf("Hello, reset!\n"); 16 | 17 | // Put the PWM block into reset 18 | reset_block(RESETS_RESET_PWM_BITS); 19 | 20 | // And bring it out 21 | unreset_block_wait(RESETS_RESET_PWM_BITS); 22 | 23 | // Put the PWM and RTC block into reset 24 | reset_block(RESETS_RESET_PWM_BITS | RESETS_RESET_RTC_BITS); 25 | 26 | // Wait for both to come out of reset 27 | unreset_block_wait(RESETS_RESET_PWM_BITS | RESETS_RESET_RTC_BITS); 28 | 29 | return 0; 30 | } 31 | /// \end::hello_reset[] 32 | -------------------------------------------------------------------------------- /pio/uart_tx/uart_tx.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | #include "hardware/pio.h" 9 | #include "uart_tx.pio.h" 10 | 11 | int main() { 12 | // We're going to use PIO to print "Hello, world!" on the same GPIO which we 13 | // normally attach UART0 to. 14 | const uint PIN_TX = 0; 15 | // This is the same as the default UART baud rate on Pico 16 | const uint SERIAL_BAUD = 115200; 17 | 18 | PIO pio = pio0; 19 | uint sm = 0; 20 | uint offset = pio_add_program(pio, &uart_tx_program); 21 | uart_tx_program_init(pio, sm, offset, PIN_TX, SERIAL_BAUD); 22 | 23 | while (true) { 24 | uart_tx_program_puts(pio, sm, "Hello, world! (from PIO!)\n"); 25 | sleep_ms(1000); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pio/spi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_spi_flash) 2 | 3 | pico_generate_pio_header(pio_spi_flash ${CMAKE_CURRENT_LIST_DIR}/spi.pio) 4 | 5 | target_sources(pio_spi_flash PRIVATE 6 | spi_flash.c 7 | pio_spi.c 8 | pio_spi.h 9 | ) 10 | 11 | target_link_libraries(pio_spi_flash PRIVATE pico_stdlib hardware_pio) 12 | pico_add_extra_outputs(pio_spi_flash) 13 | 14 | example_auto_set_url(pio_spi_flash) 15 | 16 | add_executable(pio_spi_loopback) 17 | 18 | pico_generate_pio_header(pio_spi_loopback ${CMAKE_CURRENT_LIST_DIR}/spi.pio) 19 | 20 | target_sources(pio_spi_loopback PRIVATE 21 | spi_loopback.c 22 | pio_spi.c 23 | pio_spi.h 24 | ) 25 | 26 | target_link_libraries(pio_spi_loopback PRIVATE pico_stdlib hardware_pio) 27 | pico_add_extra_outputs(pio_spi_loopback) 28 | 29 | example_auto_set_url(pio_spi_loopback) 30 | -------------------------------------------------------------------------------- /adc/hello_adc/hello_adc.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/gpio.h" 10 | #include "hardware/adc.h" 11 | 12 | int main() { 13 | stdio_init_all(); 14 | printf("ADC Example, measuring GPIO26\n"); 15 | 16 | adc_init(); 17 | 18 | // Make sure GPIO is high-impedance, no pullups etc 19 | adc_gpio_init(26); 20 | // Select ADC input 0 (GPIO26) 21 | adc_select_input(0); 22 | 23 | while (1) { 24 | // 12-bit conversion, assume max value == ADC_VREF == 3.3 V 25 | const float conversion_factor = 3.3f / (1 << 12); 26 | uint16_t result = adc_read(); 27 | printf("Raw value: 0x%03x, voltage: %f V\n", result, result * conversion_factor); 28 | sleep_ms(500); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dma/channel_irq/pio_serialiser.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program pio_serialiser 8 | 9 | ; Just serialise a stream of bits. Take 32 bits from each FIFO record. LSB-first. 10 | 11 | .wrap_target 12 | out pins, 1 13 | .wrap 14 | 15 | % c-sdk { 16 | static inline void pio_serialiser_program_init(PIO pio, uint sm, uint offset, uint data_pin, float clk_div) { 17 | pio_gpio_init(pio, data_pin); 18 | pio_sm_set_consecutive_pindirs(pio, sm, data_pin, 1, true); 19 | pio_sm_config c = pio_serialiser_program_get_default_config(offset); 20 | sm_config_set_out_pins(&c, data_pin, 1); 21 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); 22 | sm_config_set_clkdiv(&c, clk_div); 23 | sm_config_set_out_shift(&c, true, true, 32); 24 | pio_sm_init(pio, sm, offset, &c); 25 | pio_sm_set_enabled(pio, sm, true); 26 | } 27 | %} 28 | -------------------------------------------------------------------------------- /usb/host/host_cdc_msc_hid/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | add_executable(host_cdc_msc_hid) 4 | 5 | # Example source 6 | target_sources(host_cdc_msc_hid PUBLIC 7 | ${CMAKE_CURRENT_LIST_DIR}/hid_app.c 8 | ${CMAKE_CURRENT_LIST_DIR}/main.c 9 | ${CMAKE_CURRENT_LIST_DIR}/msc_app.c 10 | ) 11 | 12 | # Make sure TinyUSB can find tusb_config.h 13 | target_include_directories(host_cdc_msc_hid PUBLIC 14 | ${CMAKE_CURRENT_LIST_DIR}) 15 | 16 | # In addition to pico_stdlib required for common PicoSDK functionality, add dependency on tinyusb_host 17 | # for TinyUSB device support and tinyusb_board for the additional board support library used by the example 18 | target_link_libraries(host_cdc_msc_hid PUBLIC pico_stdlib tinyusb_host tinyusb_board) 19 | 20 | pico_add_extra_outputs(host_cdc_msc_hid) 21 | 22 | # add url via pico_set_program_url 23 | example_auto_set_url(host_cdc_msc_hid) 24 | -------------------------------------------------------------------------------- /ide/vscode/launch-remote-openocd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Pico Debug", 6 | "type":"cortex-debug", 7 | "cwd": "${workspaceRoot}", 8 | "executable": "${command:cmake.launchTargetPath}", 9 | "request": "launch", 10 | "servertype": "external", 11 | // This may need to be arm-none-eabi-gdb depending on your system 12 | "gdbPath" : "gdb-multiarch", 13 | // Connect to an already running OpenOCD instance 14 | "gdbTarget": "your-openocd:3333", 15 | "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", 16 | "runToMain": true, 17 | // Work around for stopping at main on restart 18 | "postRestartCommands": [ 19 | "break main", 20 | "continue" 21 | ] 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /pico_w/wifi_scan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_wifi_scan_background 2 | picow_wifi_scan.c 3 | ) 4 | target_include_directories(picow_wifi_scan_background PRIVATE 5 | ${CMAKE_CURRENT_LIST_DIR} 6 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 7 | ) 8 | target_link_libraries(picow_wifi_scan_background 9 | pico_cyw43_arch_lwip_threadsafe_background 10 | pico_stdlib 11 | ) 12 | 13 | pico_add_extra_outputs(picow_wifi_scan_background) 14 | 15 | add_executable(picow_wifi_scan_poll 16 | picow_wifi_scan.c 17 | ) 18 | target_include_directories(picow_wifi_scan_poll PRIVATE 19 | ${CMAKE_CURRENT_LIST_DIR} 20 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 21 | ) 22 | target_link_libraries(picow_wifi_scan_poll 23 | pico_cyw43_arch_lwip_poll 24 | pico_stdlib 25 | ) 26 | pico_add_extra_outputs(picow_wifi_scan_poll) 27 | 28 | -------------------------------------------------------------------------------- /system/hello_double_tap/hello_double_tap.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | 9 | // This is a regular old LED blinking example, however it is linked with the 10 | // `pico_bootsel_via_double_reset` library, so resetting the board twice 11 | // quickly will enter the USB bootloader. This is useful for boards which have 12 | // a reset button but no BOOTSEL, as long as you remember to always link the 13 | // `pico_bootsel_via_double_reset` library! 14 | 15 | int main() { 16 | #ifdef PICO_DEFAULT_LED_PIN 17 | const uint LED_PIN = PICO_DEFAULT_LED_PIN; 18 | gpio_init(LED_PIN); 19 | gpio_set_dir(LED_PIN, GPIO_OUT); 20 | while (true) { 21 | gpio_put(LED_PIN, 1); 22 | sleep_ms(250); 23 | gpio_put(LED_PIN, 0); 24 | sleep_ms(250); 25 | } 26 | #else 27 | while (true) { 28 | sleep_ms(250); 29 | } 30 | #endif 31 | } 32 | -------------------------------------------------------------------------------- /ide/vscode/launch-raspberrypi-swd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Pico Debug", 6 | "cwd": "${workspaceRoot}", 7 | "executable": "${command:cmake.launchTargetPath}", 8 | "request": "launch", 9 | "type": "cortex-debug", 10 | "servertype": "openocd", 11 | // This may need to be arm-none-eabi-gdb depending on your system 12 | "gdbPath" : "gdb-multiarch", 13 | "device": "RP2040", 14 | "configFiles": [ 15 | "interface/raspberrypi-swd.cfg", 16 | "target/rp2040.cfg" 17 | ], 18 | "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", 19 | "runToMain": true, 20 | // Work around for stopping at main on restart 21 | "postRestartCommands": [ 22 | "break main", 23 | "continue" 24 | ] 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /watchdog/hello_watchdog/hello_watchdog.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/watchdog.h" 10 | 11 | int main() { 12 | stdio_init_all(); 13 | 14 | if (watchdog_caused_reboot()) { 15 | printf("Rebooted by Watchdog!\n"); 16 | return 0; 17 | } else { 18 | printf("Clean boot\n"); 19 | } 20 | 21 | // Enable the watchdog, requiring the watchdog to be updated every 100ms or the chip will reboot 22 | // second arg is pause on debug which means the watchdog will pause when stepping through code 23 | watchdog_enable(100, 1); 24 | 25 | for (uint i = 0; i < 5; i++) { 26 | printf("Updating watchdog %d\n", i); 27 | watchdog_update(); 28 | } 29 | 30 | // Wait in an infinite loop and don't update the watchdog so it reboots us 31 | printf("Waiting to be rebooted by watchdog\n"); 32 | while(1); 33 | } -------------------------------------------------------------------------------- /pio/addition/addition.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program addition 8 | 9 | ; Pop two 32 bit integers from the TX FIFO, add them together, and push the 10 | ; result to the TX FIFO. Autopush/pull should be disabled as we're using 11 | ; explicit push and pull instructions. 12 | ; 13 | ; This program uses the two's complement identity x + y == ~(~x - y) 14 | 15 | pull 16 | mov x, ~osr 17 | pull 18 | mov y, osr 19 | jmp test ; this loop is equivalent to the following C code: 20 | incr: ; while (y--) 21 | jmp x-- test ; x--; 22 | test: ; This has the effect of subtracting y from x, eventually. 23 | jmp y-- incr 24 | mov isr, ~x 25 | push 26 | 27 | % c-sdk { 28 | static inline void addition_program_init(PIO pio, uint sm, uint offset) { 29 | pio_sm_config c = addition_program_get_default_config(offset); 30 | pio_sm_init(pio, sm, offset, &c); 31 | pio_sm_set_enabled(pio, sm, true); 32 | } 33 | %} 34 | -------------------------------------------------------------------------------- /pio/addition/addition.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include "pico/stdlib.h" 11 | #include "hardware/pio.h" 12 | #include "addition.pio.h" 13 | 14 | // Pop quiz: how many additions does the processor do when calling this function 15 | uint32_t do_addition(PIO pio, uint sm, uint32_t a, uint32_t b) { 16 | pio_sm_put_blocking(pio, sm, a); 17 | pio_sm_put_blocking(pio, sm, b); 18 | return pio_sm_get_blocking(pio, sm); 19 | } 20 | 21 | int main() { 22 | stdio_init_all(); 23 | 24 | PIO pio = pio0; 25 | uint sm = 0; 26 | uint offset = pio_add_program(pio, &addition_program); 27 | addition_program_init(pio, sm, offset); 28 | 29 | printf("Doing some random additions:\n"); 30 | for (int i = 0; i < 10; ++i) { 31 | uint a = rand() % 100; 32 | uint b = rand() % 100; 33 | printf("%u + %u = %u\n", a, b, do_addition(pio, sm, a, b)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pio/pio_blink/blink.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | ; SET pin 0 should be mapped to your LED GPIO 8 | 9 | .program blink 10 | pull block 11 | out y, 32 12 | .wrap_target 13 | mov x, y 14 | set pins, 1 ; Turn LED on 15 | lp1: 16 | jmp x-- lp1 ; Delay for (x + 1) cycles, x is a 32 bit number 17 | mov x, y 18 | set pins, 0 ; Turn LED off 19 | lp2: 20 | jmp x-- lp2 ; Delay for the same number of cycles again 21 | .wrap ; Blink forever! 22 | 23 | 24 | % c-sdk { 25 | // this is a raw helper function for use by the user which sets up the GPIO output, and configures the SM to output on a particular pin 26 | 27 | void blink_program_init(PIO pio, uint sm, uint offset, uint pin) { 28 | pio_gpio_init(pio, pin); 29 | pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); 30 | pio_sm_config c = blink_program_get_default_config(offset); 31 | sm_config_set_set_pins(&c, pin, 1); 32 | pio_sm_init(pio, sm, offset, &c); 33 | } 34 | %} 35 | -------------------------------------------------------------------------------- /pio/i2c/pio_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | #ifndef _PIO_I2C_H 7 | #define _PIO_I2C_H 8 | 9 | #include "i2c.pio.h" 10 | 11 | // ---------------------------------------------------------------------------- 12 | // Low-level functions 13 | 14 | void pio_i2c_start(PIO pio, uint sm); 15 | void pio_i2c_stop(PIO pio, uint sm); 16 | void pio_i2c_repstart(PIO pio, uint sm); 17 | 18 | bool pio_i2c_check_error(PIO pio, uint sm); 19 | void pio_i2c_resume_after_error(PIO pio, uint sm); 20 | 21 | // If I2C is ok, block and push data. Otherwise fall straight through. 22 | void pio_i2c_put_or_err(PIO pio, uint sm, uint16_t data); 23 | uint8_t pio_i2c_get(PIO pio, uint sm); 24 | 25 | // ---------------------------------------------------------------------------- 26 | // Transaction-level functions 27 | 28 | int pio_i2c_write_blocking(PIO pio, uint sm, uint8_t addr, uint8_t *txbuf, uint len); 29 | int pio_i2c_read_blocking(PIO pio, uint sm, uint8_t addr, uint8_t *rxbuf, uint len); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /usb/device/dev_hid_composite/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | add_executable(dev_hid_composite) 4 | 5 | target_sources(dev_hid_composite PUBLIC 6 | ${CMAKE_CURRENT_LIST_DIR}/main.c 7 | ${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c 8 | ) 9 | 10 | # Make sure TinyUSB can find tusb_config.h 11 | target_include_directories(dev_hid_composite PUBLIC 12 | ${CMAKE_CURRENT_LIST_DIR}) 13 | 14 | # In addition to pico_stdlib required for common PicoSDK functionality, add dependency on tinyusb_device 15 | # for TinyUSB device support and tinyusb_board for the additional board support library used by the example 16 | target_link_libraries(dev_hid_composite PUBLIC pico_stdlib tinyusb_device tinyusb_board) 17 | 18 | # Uncomment this line to enable fix for Errata RP2040-E5 (the fix requires use of GPIO 15) 19 | #target_compile_definitions(dev_hid_composite PUBLIC PICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1) 20 | 21 | pico_add_extra_outputs(dev_hid_composite) 22 | 23 | # add url via pico_set_program_url 24 | example_auto_set_url(dev_hid_composite) 25 | -------------------------------------------------------------------------------- /system/unique_board_id/unique_board_id.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | 9 | #include "pico/stdlib.h" 10 | #include "pico/unique_id.h" 11 | 12 | // RP2040 does not have a unique on-board ID, but this is a standard feature 13 | // on the NOR flash it boots from. There is a 1:1 association between RP2040 14 | // and the flash, so this can be used to get a 64 bit globally unique board ID 15 | // for an RP2040-based board, including Pico. 16 | // 17 | // The pico_unique_id library retrieves this unique identifier during boot and 18 | // stores it in memory, where it can be accessed at any time without 19 | // disturbing the flash XIP hardware. 20 | 21 | int main() { 22 | stdio_init_all(); 23 | 24 | pico_unique_board_id_t board_id; 25 | pico_get_unique_board_id(&board_id); 26 | 27 | printf("Unique identifier:"); 28 | for (int i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; ++i) { 29 | printf(" %02x", board_id.id[i]); 30 | } 31 | printf("\n"); 32 | } 33 | -------------------------------------------------------------------------------- /pico_w/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | if (PICO_CYW43_SUPPORTED) # set by BOARD=pico-w 4 | if (NOT TARGET pico_cyw43_arch) 5 | message("Skipping Pico W examples as support is not available") 6 | else() 7 | set(WIFI_SSID "${WIFI_SSID}" CACHE INTERNAL "WiFi SSID for examples") 8 | set(WIFI_PASSWORD "${WIFI_PASSWORD}" CACHE INTERNAL "WiFi password for examples") 9 | 10 | add_subdirectory(blink) 11 | add_subdirectory(wifi_scan) 12 | add_subdirectory(access_point) 13 | 14 | if ("${WIFI_SSID}" STREQUAL "") 15 | message("Skipping some Pico W examples as WIFI_SSID is not defined") 16 | elseif ("${WIFI_PASSWORD}" STREQUAL "") 17 | message("Skipping some Pico W examples as WIFI_PASSWORD is not defined") 18 | else() 19 | add_subdirectory(iperf) 20 | add_subdirectory(ntp_client) 21 | add_subdirectory(tcp_client) 22 | add_subdirectory(tcp_server) 23 | add_subdirectory(freertos) 24 | endif() 25 | endif() 26 | endif() 27 | -------------------------------------------------------------------------------- /pio/hello_pio/hello.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program hello 8 | 9 | ; Repeatedly get one word of data from the TX FIFO, stalling when the FIFO is 10 | ; empty. Write the least significant bit to the OUT pin group. 11 | 12 | loop: 13 | pull 14 | out pins, 1 15 | jmp loop 16 | 17 | % c-sdk { 18 | static inline void hello_program_init(PIO pio, uint sm, uint offset, uint pin) { 19 | pio_sm_config c = hello_program_get_default_config(offset); 20 | 21 | // Map the state machine's OUT pin group to one pin, namely the `pin` 22 | // parameter to this function. 23 | sm_config_set_out_pins(&c, pin, 1); 24 | // Set this pin's GPIO function (connect PIO to the pad) 25 | pio_gpio_init(pio, pin); 26 | // Set the pin direction to output at the PIO 27 | pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); 28 | 29 | // Load our configuration, and jump to the start of the program 30 | pio_sm_init(pio, sm, offset, &c); 31 | // Set the state machine running 32 | pio_sm_set_enabled(pio, sm, true); 33 | } 34 | %} 35 | -------------------------------------------------------------------------------- /pico_w/access_point/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_access_point_background 2 | picow_access_point.c 3 | dhcpserver/dhcpserver.c 4 | ) 5 | 6 | target_include_directories(picow_access_point_background PRIVATE 7 | ${CMAKE_CURRENT_LIST_DIR} 8 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 9 | ${CMAKE_CURRENT_LIST_DIR}/dhcpserver 10 | ) 11 | 12 | target_link_libraries(picow_access_point_background 13 | pico_cyw43_arch_lwip_threadsafe_background 14 | pico_stdlib 15 | ) 16 | 17 | pico_add_extra_outputs(picow_access_point_background) 18 | 19 | add_executable(picow_access_point_poll 20 | picow_access_point.c 21 | dhcpserver/dhcpserver.c 22 | ) 23 | target_include_directories(picow_access_point_poll PRIVATE 24 | ${CMAKE_CURRENT_LIST_DIR} 25 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 26 | ${CMAKE_CURRENT_LIST_DIR}/dhcpserver 27 | ) 28 | target_link_libraries(picow_access_point_poll 29 | pico_cyw43_arch_lwip_poll 30 | pico_stdlib 31 | ) 32 | pico_add_extra_outputs(picow_access_point_poll) 33 | 34 | -------------------------------------------------------------------------------- /pio/pwm/pwm.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | ; Side-set pin 0 is used for PWM output 8 | 9 | .program pwm 10 | .side_set 1 opt 11 | 12 | pull noblock side 0 ; Pull from FIFO to OSR if available, else copy X to OSR. 13 | mov x, osr ; Copy most-recently-pulled value back to scratch X 14 | mov y, isr ; ISR contains PWM period. Y used as counter. 15 | countloop: 16 | jmp x!=y noset ; Set pin high if X == Y, keep the two paths length matched 17 | jmp skip side 1 18 | noset: 19 | nop ; Single dummy cycle to keep the two paths the same length 20 | skip: 21 | jmp y-- countloop ; Loop until Y hits 0, then pull a fresh PWM value from FIFO 22 | 23 | % c-sdk { 24 | static inline void pwm_program_init(PIO pio, uint sm, uint offset, uint pin) { 25 | pio_gpio_init(pio, pin); 26 | pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); 27 | pio_sm_config c = pwm_program_get_default_config(offset); 28 | sm_config_set_sideset_pins(&c, pin); 29 | pio_sm_init(pio, sm, offset, &c); 30 | } 31 | %} 32 | -------------------------------------------------------------------------------- /pwm/hello_pwm/hello_pwm.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // Output PWM signals on pins 0 and 1 8 | 9 | #include "pico/stdlib.h" 10 | #include "hardware/pwm.h" 11 | 12 | int main() { 13 | /// \tag::setup_pwm[] 14 | 15 | // Tell GPIO 0 and 1 they are allocated to the PWM 16 | gpio_set_function(0, GPIO_FUNC_PWM); 17 | gpio_set_function(1, GPIO_FUNC_PWM); 18 | 19 | // Find out which PWM slice is connected to GPIO 0 (it's slice 0) 20 | uint slice_num = pwm_gpio_to_slice_num(0); 21 | 22 | // Set period of 4 cycles (0 to 3 inclusive) 23 | pwm_set_wrap(slice_num, 3); 24 | // Set channel A output high for one cycle before dropping 25 | pwm_set_chan_level(slice_num, PWM_CHAN_A, 1); 26 | // Set initial B output high for three cycles before dropping 27 | pwm_set_chan_level(slice_num, PWM_CHAN_B, 3); 28 | // Set the PWM running 29 | pwm_set_enabled(slice_num, true); 30 | /// \end::setup_pwm[] 31 | 32 | // Note we could also use pwm_set_gpio_level(gpio, x) which looks up the 33 | // correct slice and channel for a given GPIO. 34 | } 35 | -------------------------------------------------------------------------------- /pico_w/access_point/dhcpserver/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2022 Damien P. George 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /usb/host/host_cdc_msc_hid/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018, hathach (tinyusb.org) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /multicore/hello_multicore/multicore.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 "pico/multicore.h" 10 | 11 | #define FLAG_VALUE 123 12 | 13 | void core1_entry() { 14 | 15 | multicore_fifo_push_blocking(FLAG_VALUE); 16 | 17 | uint32_t g = multicore_fifo_pop_blocking(); 18 | 19 | if (g != FLAG_VALUE) 20 | printf("Hmm, that's not right on core 1!\n"); 21 | else 22 | printf("Its all gone well on core 1!"); 23 | 24 | while (1) 25 | tight_loop_contents(); 26 | } 27 | 28 | int main() { 29 | stdio_init_all(); 30 | printf("Hello, multicore!\n"); 31 | 32 | /// \tag::setup_multicore[] 33 | 34 | multicore_launch_core1(core1_entry); 35 | 36 | // Wait for it to start up 37 | 38 | uint32_t g = multicore_fifo_pop_blocking(); 39 | 40 | if (g != FLAG_VALUE) 41 | printf("Hmm, that's not right on core 0!\n"); 42 | else { 43 | multicore_fifo_push_blocking(FLAG_VALUE); 44 | printf("It's all gone well on core 0!"); 45 | } 46 | 47 | /// \end::setup_multicore[] 48 | } 49 | -------------------------------------------------------------------------------- /pio/pio_blink/blink.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | 9 | #include "pico/stdlib.h" 10 | #include "hardware/pio.h" 11 | #include "hardware/clocks.h" 12 | #include "blink.pio.h" 13 | 14 | void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq); 15 | 16 | int main() { 17 | setup_default_uart(); 18 | 19 | // todo get free sm 20 | PIO pio = pio0; 21 | uint offset = pio_add_program(pio, &blink_program); 22 | printf("Loaded program at %d\n", offset); 23 | 24 | blink_pin_forever(pio, 0, offset, 0, 3); 25 | blink_pin_forever(pio, 1, offset, 6, 4); 26 | blink_pin_forever(pio, 2, offset, 11, 1); 27 | } 28 | 29 | void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq) { 30 | blink_program_init(pio, sm, offset, pin); 31 | pio_sm_set_enabled(pio, sm, true); 32 | 33 | printf("Blinking pin %d at %d Hz\n", pin, freq); 34 | 35 | // PIO counter program takes 3 more cycles in total than we pass as 36 | // input (wait for n + 1; mov; jmp) 37 | pio->txf[sm] = (clock_get_hz(clk_sys) / (2 * freq)) - 3; 38 | } 39 | -------------------------------------------------------------------------------- /usb/device/dev_hid_composite/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018, hathach (tinyusb.org) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /pio/ws2812/generated/ws2812.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------- # 2 | # This file is autogenerated by pioasm; do not edit! # 3 | # -------------------------------------------------- # 4 | 5 | import rp2 6 | from machine import Pin 7 | # ------ # 8 | # ws2812 # 9 | # ------ # 10 | 11 | ws2812_T1 = 2 12 | ws2812_T2 = 5 13 | ws2812_T3 = 3 14 | 15 | @rp2.asm_pio(sideset_init=pico.PIO.OUT_HIGH, out_init=pico.PIO.OUT_HIGH, out_shiftdir=1) 16 | def ws2812(): 17 | wrap_target() 18 | label("0") 19 | out(x, 1) .side(0) [2] # 0 20 | jmp(not_x, "3") .side(1) [1] # 1 21 | jmp("0") .side(1) [4] # 2 22 | label("3") 23 | nop() .side(0) [4] # 3 24 | wrap() 25 | 26 | 27 | 28 | # --------------- # 29 | # ws2812_parallel # 30 | # --------------- # 31 | 32 | ws2812_parallel_T1 = 2 33 | ws2812_parallel_T2 = 5 34 | ws2812_parallel_T3 = 3 35 | 36 | @rp2.asm_pio() 37 | def ws2812_parallel(): 38 | wrap_target() 39 | out(x, 32) # 0 40 | mov(pins, invert(null)) [1] # 1 41 | mov(pins, x) [4] # 2 42 | mov(pins, null) [1] # 3 43 | wrap() 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /pio/hub75/Readme.md: -------------------------------------------------------------------------------- 1 | HUB75E Pinout: 2 | 3 | ``` 4 | /-----\ 5 | R0 | o o | G0 6 | B0 | o o | GND 7 | R1 | o o | G1 8 | B1 \ o o | E 9 | A / o o | B 10 | C | o o | D 11 | CLK | o o | STB 12 | OEn | o o | GND 13 | \-----/ 14 | ``` 15 | 16 | Wiring: 17 | 18 | ``` 19 | Must be contiguous, in order: 20 | R0 - GPIO0 21 | G0 - GPIO1 22 | B0 - GPIO2 23 | R1 - GPIO3 24 | G1 - GPIO4 25 | B1 - GPIO5 26 | 27 | Must be contiguous, somewhat ok to change order: 28 | A - GPIO6 29 | B - GPIO7 30 | C - GPIO8 31 | D - GPIO9 32 | E - GPIO10 33 | 34 | Can be anywhere: 35 | CLK - GPIO11 36 | 37 | Must be contiguous, in order: 38 | STB - GPIO12 39 | OEn - GPIO13 40 | ``` 41 | 42 | This is a 1/32nd scan panel. The inputs A, B, C, D, E select one of 32 rows, starting at the top and working down (assuming the first pixel to be shifted is the one on the left of the screen, even though this is the "far end" of the shift register). R0, B0, G0 contain pixel data for the upper half of the screen. R1, G1, B1 contain pixel data for the lower half of the screen, which is scanned simultaneously with the upper half. 43 | 44 | Image credit for mountains_128x64.png: Paul Gilmore, found on [this wikimedia page](https://commons.wikimedia.org/wiki/File:Mountain_lake_dam.jpg) 45 | 46 | -------------------------------------------------------------------------------- /pico_w/ntp_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_ntp_client_background 2 | picow_ntp_client.c 3 | ) 4 | target_compile_definitions(picow_ntp_client_background PRIVATE 5 | WIFI_SSID=\"${WIFI_SSID}\" 6 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 7 | ) 8 | target_include_directories(picow_ntp_client_background PRIVATE 9 | ${CMAKE_CURRENT_LIST_DIR} 10 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 11 | ) 12 | target_link_libraries(picow_ntp_client_background 13 | pico_cyw43_arch_lwip_threadsafe_background 14 | pico_stdlib 15 | ) 16 | 17 | pico_add_extra_outputs(picow_ntp_client_background) 18 | 19 | add_executable(picow_ntp_client_poll 20 | picow_ntp_client.c 21 | ) 22 | target_compile_definitions(picow_ntp_client_poll PRIVATE 23 | WIFI_SSID=\"${WIFI_SSID}\" 24 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 25 | ) 26 | target_include_directories(picow_ntp_client_poll PRIVATE 27 | ${CMAKE_CURRENT_LIST_DIR} 28 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 29 | ) 30 | target_link_libraries(picow_ntp_client_poll 31 | pico_cyw43_arch_lwip_poll 32 | pico_stdlib 33 | ) 34 | pico_add_extra_outputs(picow_ntp_client_poll) 35 | 36 | -------------------------------------------------------------------------------- /pio/i2c/i2c_bus_scan.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "pico/stdlib.h" 4 | #include "pio_i2c.h" 5 | 6 | #define PIN_SDA 2 7 | #define PIN_SCL 3 8 | 9 | bool reserved_addr(uint8_t addr) { 10 | return (addr & 0x78) == 0 || (addr & 0x78) == 0x78; 11 | } 12 | 13 | int main() { 14 | stdio_init_all(); 15 | 16 | PIO pio = pio0; 17 | uint sm = 0; 18 | uint offset = pio_add_program(pio, &i2c_program); 19 | i2c_program_init(pio, sm, offset, PIN_SDA, PIN_SCL); 20 | 21 | printf("\nPIO I2C Bus Scan\n"); 22 | printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n"); 23 | 24 | for (int addr = 0; addr < (1 << 7); ++addr) { 25 | if (addr % 16 == 0) { 26 | printf("%02x ", addr); 27 | } 28 | // Perform a 0-byte read from the probe address. The read function 29 | // returns a negative result NAK'd any time other than the last data 30 | // byte. Skip over reserved addresses. 31 | int result; 32 | if (reserved_addr(addr)) 33 | result = -1; 34 | else 35 | result = pio_i2c_read_blocking(pio, sm, addr, NULL, 0); 36 | 37 | printf(result < 0 ? "." : "@"); 38 | printf(addr % 16 == 15 ? "\n" : " "); 39 | } 40 | printf("Done.\n"); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /adc/joystick_display/joystick_display.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_x_raw = adc_read(); 21 | adc_select_input(1); 22 | uint adc_y_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 (int i = 0; i < bar_width; ++i) 32 | putchar( i == bar_x_pos ? 'o' : ' '); 33 | printf("] Y: ["); 34 | for (int i = 0; i < bar_width; ++i) 35 | putchar( i == bar_y_pos ? 'o' : ' '); 36 | printf("]"); 37 | sleep_ms(50); 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pico_w/tcp_server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_tcpip_server_background 2 | picow_tcp_server.c 3 | ) 4 | target_compile_definitions(picow_tcpip_server_background PRIVATE 5 | WIFI_SSID=\"${WIFI_SSID}\" 6 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 7 | ) 8 | target_include_directories(picow_tcpip_server_background PRIVATE 9 | ${CMAKE_CURRENT_LIST_DIR} 10 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 11 | ) 12 | target_link_libraries(picow_tcpip_server_background 13 | pico_cyw43_arch_lwip_threadsafe_background 14 | pico_stdlib 15 | ) 16 | 17 | pico_add_extra_outputs(picow_tcpip_server_background) 18 | 19 | add_executable(picow_tcpip_server_poll 20 | picow_tcp_server.c 21 | ) 22 | target_compile_definitions(picow_tcpip_server_poll PRIVATE 23 | WIFI_SSID=\"${WIFI_SSID}\" 24 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 25 | ) 26 | target_include_directories(picow_tcpip_server_poll PRIVATE 27 | ${CMAKE_CURRENT_LIST_DIR} 28 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 29 | ) 30 | target_link_libraries(picow_tcpip_server_poll 31 | pico_cyw43_arch_lwip_poll 32 | pico_stdlib 33 | ) 34 | pico_add_extra_outputs(picow_tcpip_server_poll) 35 | -------------------------------------------------------------------------------- /pio/squarewave/generated/squarewave.pio.h: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------- // 2 | // This file is autogenerated by pioasm; do not edit! // 3 | // -------------------------------------------------- // 4 | 5 | #pragma once 6 | 7 | #if !PICO_NO_HARDWARE 8 | #include "hardware/pio.h" 9 | #endif 10 | 11 | // ---------- // 12 | // squarewave // 13 | // ---------- // 14 | 15 | #define squarewave_wrap_target 0 16 | #define squarewave_wrap 3 17 | 18 | static const uint16_t squarewave_program_instructions[] = { 19 | // .wrap_target 20 | 0xe081, // 0: set pindirs, 1 21 | 0xe101, // 1: set pins, 1 [1] 22 | 0xe000, // 2: set pins, 0 23 | 0x0001, // 3: jmp 1 24 | // .wrap 25 | }; 26 | 27 | #if !PICO_NO_HARDWARE 28 | static const struct pio_program squarewave_program = { 29 | .instructions = squarewave_program_instructions, 30 | .length = 4, 31 | .origin = -1, 32 | }; 33 | 34 | static inline pio_sm_config squarewave_program_get_default_config(uint offset) { 35 | pio_sm_config c = pio_get_default_sm_config(); 36 | sm_config_set_wrap(&c, offset + squarewave_wrap_target, offset + squarewave_wrap); 37 | return c; 38 | } 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /pio/squarewave/generated/squarewave_wrap.pio.h: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------- // 2 | // This file is autogenerated by pioasm; do not edit! // 3 | // -------------------------------------------------- // 4 | 5 | #pragma once 6 | 7 | #if !PICO_NO_HARDWARE 8 | #include "hardware/pio.h" 9 | #endif 10 | 11 | // --------------- // 12 | // squarewave_wrap // 13 | // --------------- // 14 | 15 | #define squarewave_wrap_wrap_target 1 16 | #define squarewave_wrap_wrap 2 17 | 18 | static const uint16_t squarewave_wrap_program_instructions[] = { 19 | 0xe081, // 0: set pindirs, 1 20 | // .wrap_target 21 | 0xe101, // 1: set pins, 1 [1] 22 | 0xe100, // 2: set pins, 0 [1] 23 | // .wrap 24 | }; 25 | 26 | #if !PICO_NO_HARDWARE 27 | static const struct pio_program squarewave_wrap_program = { 28 | .instructions = squarewave_wrap_program_instructions, 29 | .length = 3, 30 | .origin = -1, 31 | }; 32 | 33 | static inline pio_sm_config squarewave_wrap_program_get_default_config(uint offset) { 34 | pio_sm_config c = pio_get_default_sm_config(); 35 | sm_config_set_wrap(&c, offset + squarewave_wrap_wrap_target, offset + squarewave_wrap_wrap); 36 | return c; 37 | } 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /usb/device/dev_lowlevel/dev_lowlevel_loopback.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # 4 | # Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 5 | # 6 | # SPDX-License-Identifier: BSD-3-Clause 7 | # 8 | 9 | # sudo pip3 install pyusb 10 | 11 | import usb.core 12 | import usb.util 13 | 14 | # find our device 15 | dev = usb.core.find(idVendor=0x0000, idProduct=0x0001) 16 | 17 | # was it found? 18 | if dev is None: 19 | raise ValueError('Device not found') 20 | 21 | # get an endpoint instance 22 | cfg = dev.get_active_configuration() 23 | intf = cfg[(0, 0)] 24 | 25 | outep = usb.util.find_descriptor( 26 | intf, 27 | # match the first OUT endpoint 28 | custom_match= \ 29 | lambda e: \ 30 | usb.util.endpoint_direction(e.bEndpointAddress) == \ 31 | usb.util.ENDPOINT_OUT) 32 | 33 | inep = usb.util.find_descriptor( 34 | intf, 35 | # match the first IN endpoint 36 | custom_match= \ 37 | lambda e: \ 38 | usb.util.endpoint_direction(e.bEndpointAddress) == \ 39 | usb.util.ENDPOINT_IN) 40 | 41 | assert inep is not None 42 | assert outep is not None 43 | 44 | test_string = "Hello World!" 45 | outep.write(test_string) 46 | from_device = inep.read(len(test_string)) 47 | 48 | print("Device Says: {}".format(''.join([chr(x) for x in from_device]))) 49 | -------------------------------------------------------------------------------- /clocks/hello_resus/hello_resus.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "pico/stdlib.h" 9 | #include "hardware/clocks.h" 10 | #include "hardware/pll.h" 11 | 12 | volatile bool seen_resus; 13 | 14 | void resus_callback(void) { 15 | // Reconfigure PLL sys back to the default state of 1500 / 6 / 2 = 125MHz 16 | pll_init(pll_sys, 1, 1500 * MHZ, 6, 2); 17 | 18 | // CLK SYS = PLL SYS (125MHz) / 1 = 125MHz 19 | clock_configure(clk_sys, 20 | CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLKSRC_CLK_SYS_AUX, 21 | CLOCKS_CLK_SYS_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS, 22 | 125 * MHZ, 23 | 125 * MHZ); 24 | 25 | // Reconfigure uart as clocks have changed 26 | stdio_init_all(); 27 | printf("Resus event fired\n"); 28 | 29 | // Wait for uart output to finish 30 | uart_default_tx_wait_blocking(); 31 | 32 | seen_resus = true; 33 | } 34 | 35 | int main() { 36 | stdio_init_all(); 37 | printf("Hello resus\n"); 38 | 39 | seen_resus = false; 40 | 41 | clocks_enable_resus(&resus_callback); 42 | // Break PLL sys 43 | pll_deinit(pll_sys); 44 | 45 | while(!seen_resus); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /adc/dma_capture/resistor_dac.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program resistor_dac_5bit 8 | 9 | ; Drive one of the 5-bit resistor DACs on the VGA reference board. (this isn't 10 | ; a good way to do VGA -- just want a nice sawtooth for the ADC example!) 11 | 12 | out pins, 5 13 | 14 | 15 | 16 | % c-sdk { 17 | #include "hardware/clocks.h" 18 | static inline void resistor_dac_5bit_program_init(PIO pio, uint sm, uint offset, 19 | uint sample_rate_hz, uint pin_base) { 20 | 21 | pio_sm_set_pins_with_mask(pio, sm, 0, 0x1fu << pin_base); 22 | pio_sm_set_pindirs_with_mask(pio, sm, ~0u, 0x1fu << pin_base); 23 | for (int i = 0; i < 5; ++i) 24 | pio_gpio_init(pio, pin_base + i); 25 | 26 | pio_sm_config c = resistor_dac_5bit_program_get_default_config(offset); 27 | sm_config_set_out_pins(&c, pin_base, 5); 28 | // Shift to right, autopull threshold 5 29 | sm_config_set_out_shift(&c, true, true, 5); 30 | // Deeper FIFO as we're not doing any RX 31 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); 32 | float div = (float)clock_get_hz(clk_sys) / sample_rate_hz; 33 | sm_config_set_clkdiv(&c, div); 34 | 35 | pio_sm_init(pio, sm, offset, &c); 36 | pio_sm_set_enabled(pio, sm, true); 37 | } 38 | %} 39 | -------------------------------------------------------------------------------- /pico_w/iperf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_iperf_server_background 2 | picow_iperf.c 3 | ) 4 | target_compile_definitions(picow_iperf_server_background PRIVATE 5 | WIFI_SSID=\"${WIFI_SSID}\" 6 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 7 | ) 8 | target_include_directories(picow_iperf_server_background PRIVATE 9 | ${CMAKE_CURRENT_LIST_DIR} 10 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 11 | ) 12 | target_link_libraries(picow_iperf_server_background 13 | pico_cyw43_arch_lwip_threadsafe_background 14 | pico_stdlib 15 | pico_lwip_iperf 16 | ) 17 | 18 | pico_add_extra_outputs(picow_iperf_server_background) 19 | 20 | add_executable(picow_iperf_server_poll 21 | picow_iperf.c 22 | ) 23 | target_compile_definitions(picow_iperf_server_poll PRIVATE 24 | WIFI_SSID=\"${WIFI_SSID}\" 25 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 26 | ) 27 | target_include_directories(picow_iperf_server_poll PRIVATE 28 | ${CMAKE_CURRENT_LIST_DIR} 29 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 30 | ) 31 | target_link_libraries(picow_iperf_server_poll 32 | pico_cyw43_arch_lwip_poll 33 | pico_stdlib 34 | pico_lwip_iperf 35 | ) 36 | pico_add_extra_outputs(picow_iperf_server_poll) 37 | 38 | -------------------------------------------------------------------------------- /uart/hello_uart/hello_uart.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | 8 | #include 9 | #include "pico/stdlib.h" 10 | #include "hardware/uart.h" 11 | 12 | /// \tag::hello_uart[] 13 | 14 | #define UART_ID uart0 15 | #define BAUD_RATE 115200 16 | 17 | // We are using pins 0 and 1, but see the GPIO function select table in the 18 | // datasheet for information on which other pins can be used. 19 | #define UART_TX_PIN 0 20 | #define UART_RX_PIN 1 21 | 22 | int main() { 23 | // Set up our UART with the required speed. 24 | uart_init(UART_ID, BAUD_RATE); 25 | 26 | // Set the TX and RX pins by using the function select on the GPIO 27 | // Set datasheet for more information on function select 28 | gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART); 29 | gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART); 30 | 31 | // Use some the various UART functions to send out data 32 | // In a default system, printf will also output via the default UART 33 | 34 | // Send out a character without any conversions 35 | uart_putc_raw(UART_ID, 'A'); 36 | 37 | // Send out a character but do CR/LF conversions 38 | uart_putc(UART_ID, 'B'); 39 | 40 | // Send out a string, with CR/LF conversions 41 | uart_puts(UART_ID, " Hello, UART!\n"); 42 | } 43 | 44 | /// \end::hello_uart[] 45 | -------------------------------------------------------------------------------- /i2c/pcf8523_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a PCF8523 Real Time Clock via I2C 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to the PCF8523 Real Time Clock 4 | 5 | This example allows you to initialise the current time and date and then displays it every half-second. Additionally it lets you set an alarm for a particular time and date and raises an alert accordingly. More information about the module is available at https://learn.adafruit.com/adafruit-pcf8523-real-time-clock. 6 | 7 | == Wiring information 8 | 9 | Wiring up the device requires 4 jumpers, to connect VDD, GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the 5V pin. 10 | 11 | [[pcf8523_i2c_wiring]] 12 | [pdfwidth=75%] 13 | .Wiring Diagram for PCF8523. 14 | image::pc8523_i2c.png[] 15 | 16 | == List of Files 17 | 18 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 19 | pcf8523_i2c.c:: The example code. 20 | 21 | == Bill of Materials 22 | 23 | .A list of materials required for the example 24 | [[pcf8523-bom-table]] 25 | [cols=3] 26 | |=== 27 | | *Item* | *Quantity* | Details 28 | | Breadboard | 1 | generic part 29 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 30 | | PCF8523 board| 1 | https://www.adafruit.com/product/3295 31 | | M/M Jumper wires | 4 | generic part 32 | |=== 33 | 34 | -------------------------------------------------------------------------------- /rtc/hello_rtc/hello_rtc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "hardware/rtc.h" 9 | #include "pico/stdlib.h" 10 | #include "pico/util/datetime.h" 11 | 12 | /// \tag::hello_rtc_main[] 13 | int main() { 14 | stdio_init_all(); 15 | printf("Hello RTC!\n"); 16 | 17 | char datetime_buf[256]; 18 | char *datetime_str = &datetime_buf[0]; 19 | 20 | // Start on Friday 5th of June 2020 15:45:00 21 | datetime_t t = { 22 | .year = 2020, 23 | .month = 06, 24 | .day = 05, 25 | .dotw = 5, // 0 is Sunday, so 5 is Friday 26 | .hour = 15, 27 | .min = 45, 28 | .sec = 00 29 | }; 30 | 31 | // Start the RTC 32 | rtc_init(); 33 | rtc_set_datetime(&t); 34 | 35 | // clk_sys is >2000x faster than clk_rtc, so datetime is not updated immediately when rtc_get_datetime() is called. 36 | // tbe delay is up to 3 RTC clock cycles (which is 64us with the default clock settings) 37 | sleep_us(64); 38 | 39 | // Print the time 40 | while (true) { 41 | rtc_get_datetime(&t); 42 | datetime_to_str(datetime_str, sizeof(datetime_buf), &t); 43 | printf("\r%s ", datetime_str); 44 | sleep_ms(100); 45 | } 46 | 47 | return 0; 48 | } 49 | /// \end::hello_rtc_main[] 50 | -------------------------------------------------------------------------------- /pio/manchester_encoding/manchester_encoding.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | 9 | #include "pico/stdlib.h" 10 | #include "hardware/pio.h" 11 | #include "manchester_encoding.pio.h" 12 | 13 | // Manchester serial transmit/receive example. This transmits and receives at 14 | // 10 Mbps if sysclk is 120 MHz. 15 | 16 | // Need to connect a wire from GPIO2 -> GPIO3 17 | const uint pin_tx = 2; 18 | const uint pin_rx = 3; 19 | 20 | int main() { 21 | stdio_init_all(); 22 | 23 | PIO pio = pio0; 24 | uint sm_tx = 0; 25 | uint sm_rx = 1; 26 | 27 | uint offset_tx = pio_add_program(pio, &manchester_tx_program); 28 | uint offset_rx = pio_add_program(pio, &manchester_rx_program); 29 | printf("Transmit program loaded at %d\n", offset_tx); 30 | printf("Receive program loaded at %d\n", offset_rx); 31 | 32 | manchester_tx_program_init(pio, sm_tx, offset_tx, pin_tx, 1.f); 33 | manchester_rx_program_init(pio, sm_rx, offset_rx, pin_rx, 1.f); 34 | 35 | pio_sm_set_enabled(pio, sm_tx, false); 36 | pio_sm_put_blocking(pio, sm_tx, 0); 37 | pio_sm_put_blocking(pio, sm_tx, 0x0ff0a55a); 38 | pio_sm_put_blocking(pio, sm_tx, 0x12345678); 39 | pio_sm_set_enabled(pio, sm_tx, true); 40 | 41 | for (int i = 0; i < 3; ++i) 42 | printf("%08x\n", pio_sm_get_blocking(pio, sm_rx)); 43 | } 44 | -------------------------------------------------------------------------------- /i2c/mcp9808_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a MCP9808 digital temperature sensor via I2C 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to the MCP9808 digital temperature sensor board. 4 | 5 | This example reads the ambient temperature value each second from the sensor and sets upper, lower and critical limits for the temperature and checks if alerts need to be raised. The CONFIG register can also be used to check for an alert if the critical temperature is surpassed. 6 | 7 | == Wiring information 8 | 9 | Wiring up the device requires 4 jumpers, to connect VDD, GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the VSYS pin. 10 | 11 | [[mcp9808_i2c_wiring]] 12 | [pdfwidth=75%] 13 | .Wiring Diagram for MCP9808. 14 | image::mcp9808_i2c.png[] 15 | 16 | == List of Files 17 | 18 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 19 | mcp9808_i2c.c:: The example code. 20 | 21 | == Bill of Materials 22 | 23 | .A list of materials required for the example 24 | [[mcp9808-bom-table]] 25 | [cols=3] 26 | |=== 27 | | *Item* | *Quantity* | Details 28 | | Breadboard | 1 | generic part 29 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 30 | | MCP9808 board| 1 | https://www.adafruit.com/product/1782 31 | | M/M Jumper wires | 4 | generic part 32 | |=== 33 | 34 | 35 | -------------------------------------------------------------------------------- /adc/microphone_adc/microphone_adc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "pico/stdlib.h" 9 | #include "hardware/gpio.h" 10 | #include "hardware/adc.h" 11 | #include "hardware/uart.h" 12 | #include "pico/binary_info.h" 13 | 14 | /* Example code to extract analog values from a microphone using the ADC 15 | with accompanying Python file to plot these values 16 | 17 | Connections on Raspberry Pi Pico board, other boards may vary. 18 | 19 | GPIO 26/ADC0 (pin 31)-> AOUT or AUD on microphone board 20 | 3.3v (pin 36) -> VCC on microphone board 21 | GND (pin 38) -> GND on microphone board 22 | */ 23 | 24 | #define ADC_NUM 0 25 | #define ADC_PIN (26 + ADC_NUM) 26 | #define ADC_VREF 3.3 27 | #define ADC_RANGE (1 << 12) 28 | #define ADC_CONVERT (ADC_VREF / (ADC_RANGE - 1)) 29 | 30 | int main() { 31 | stdio_init_all(); 32 | printf("Beep boop, listening...\n"); 33 | 34 | bi_decl(bi_program_description("Analog microphone example for Raspberry Pi Pico")); // for picotool 35 | bi_decl(bi_1pin_with_name(ADC_PIN, "ADC input pin")); 36 | 37 | adc_init(); 38 | adc_gpio_init( ADC_PIN); 39 | adc_select_input( ADC_NUM); 40 | 41 | uint adc_raw; 42 | while (1) { 43 | adc_raw = adc_read(); // raw voltage from ADC 44 | printf("%.2f\n", adc_raw * ADC_CONVERT); 45 | sleep_ms(10); 46 | } 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /pio/differential_manchester/differential_manchester.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | 9 | #include "pico/stdlib.h" 10 | #include "hardware/pio.h" 11 | #include "differential_manchester.pio.h" 12 | 13 | // Differential serial transmit/receive example 14 | // Need to connect a wire from GPIO2 -> GPIO3 15 | 16 | const uint pin_tx = 2; 17 | const uint pin_rx = 3; 18 | 19 | int main() { 20 | stdio_init_all(); 21 | 22 | PIO pio = pio0; 23 | uint sm_tx = 0; 24 | uint sm_rx = 1; 25 | 26 | uint offset_tx = pio_add_program(pio, &differential_manchester_tx_program); 27 | uint offset_rx = pio_add_program(pio, &differential_manchester_rx_program); 28 | printf("Transmit program loaded at %d\n", offset_tx); 29 | printf("Receive program loaded at %d\n", offset_rx); 30 | 31 | // Configure state machines, set bit rate at 5 Mbps 32 | differential_manchester_tx_program_init(pio, sm_tx, offset_tx, pin_tx, 125.f / (16 * 5)); 33 | differential_manchester_rx_program_init(pio, sm_rx, offset_rx, pin_rx, 125.f / (16 * 5)); 34 | 35 | pio_sm_set_enabled(pio, sm_tx, false); 36 | pio_sm_put_blocking(pio, sm_tx, 0); 37 | pio_sm_put_blocking(pio, sm_tx, 0x0ff0a55a); 38 | pio_sm_put_blocking(pio, sm_tx, 0x12345678); 39 | pio_sm_set_enabled(pio, sm_tx, true); 40 | 41 | for (int i = 0; i < 3; ++i) 42 | printf("%08x\n", pio_sm_get_blocking(pio, sm_rx)); 43 | } 44 | -------------------------------------------------------------------------------- /cmake/build_variants/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 1 Create an INTERFACE library aggregating all the common parts of the application 2 | add_library(common_stuff INTERFACE) 3 | 4 | # note cmake policy is to use absolute paths for interface libraries. 5 | target_sources(common_stuff INTERFACE 6 | ${CMAKE_CURRENT_LIST_DIR}/main.c 7 | ${CMAKE_CURRENT_LIST_DIR}/other.c 8 | ) 9 | 10 | target_compile_definitions(common_stuff INTERFACE 11 | A_DEFINE_THAT_IS_SHARED=123 12 | ) 13 | 14 | # can include library dependencies here 15 | target_link_libraries(common_stuff INTERFACE 16 | pico_stdlib 17 | ) 18 | 19 | # 2 Create the first executable including all the common stuff... 20 | # we can set compile definitions for this executable here too. Because 21 | # we depend on an INTERFACE library (common_stuff) we 22 | # will pick up all of its definitions/dependencies too 23 | add_executable(build_variant1) 24 | target_link_libraries(build_variant1 common_stuff) 25 | target_compile_definitions(build_variant1 PRIVATE 26 | A_DEFINE_THAT_IS_NOT_SHARED=456) 27 | pico_add_extra_outputs(build_variant1) 28 | 29 | # 3 Create a second executable including all the common stuff 30 | # this version also sets the DO_EXTRA define 31 | add_executable(build_variant2) 32 | target_link_libraries(build_variant2 common_stuff) 33 | target_compile_definitions(build_variant2 PRIVATE 34 | A_DEFINE_THAT_IS_NOT_SHARED=789 35 | DO_EXTRA) 36 | pico_add_extra_outputs(build_variant2) 37 | 38 | -------------------------------------------------------------------------------- /pio/hello_pio/hello.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include "pico/stdlib.h" 8 | #include "hardware/pio.h" 9 | // Our assembled program: 10 | #include "hello.pio.h" 11 | 12 | int main() { 13 | #ifndef PICO_DEFAULT_LED_PIN 14 | #warning pio/hello_pio example requires a board with a regular LED 15 | #else 16 | // Choose which PIO instance to use (there are two instances) 17 | PIO pio = pio0; 18 | 19 | // Our assembled program needs to be loaded into this PIO's instruction 20 | // memory. This SDK function will find a location (offset) in the 21 | // instruction memory where there is enough space for our program. We need 22 | // to remember this location! 23 | uint offset = pio_add_program(pio, &hello_program); 24 | 25 | // Find a free state machine on our chosen PIO (erroring if there are 26 | // none). Configure it to run our program, and start it, using the 27 | // helper function we included in our .pio file. 28 | uint sm = pio_claim_unused_sm(pio, true); 29 | hello_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN); 30 | 31 | // The state machine is now running. Any value we push to its TX FIFO will 32 | // appear on the LED pin. 33 | while (true) { 34 | // Blink 35 | pio_sm_put_blocking(pio, sm, 1); 36 | sleep_ms(500); 37 | // Blonk 38 | pio_sm_put_blocking(pio, sm, 0); 39 | sleep_ms(500); 40 | } 41 | #endif 42 | } 43 | -------------------------------------------------------------------------------- /rtc/rtc_alarm/rtc_alarm.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "hardware/rtc.h" 9 | #include "pico/stdlib.h" 10 | #include "pico/util/datetime.h" 11 | 12 | static volatile bool fired = false; 13 | 14 | static void alarm_callback(void) { 15 | datetime_t t = {0}; 16 | rtc_get_datetime(&t); 17 | char datetime_buf[256]; 18 | char *datetime_str = &datetime_buf[0]; 19 | datetime_to_str(datetime_str, sizeof(datetime_buf), &t); 20 | printf("Alarm Fired At %s\n", datetime_str); 21 | stdio_flush(); 22 | fired = true; 23 | } 24 | 25 | int main() { 26 | stdio_init_all(); 27 | printf("RTC Alarm!\n"); 28 | 29 | // Start on Wednesday 13th January 2021 11:20:00 30 | datetime_t t = { 31 | .year = 2020, 32 | .month = 01, 33 | .day = 13, 34 | .dotw = 3, // 0 is Sunday, so 3 is Wednesday 35 | .hour = 11, 36 | .min = 20, 37 | .sec = 00 38 | }; 39 | 40 | // Start the RTC 41 | rtc_init(); 42 | rtc_set_datetime(&t); 43 | 44 | // Alarm 5 seconds later 45 | datetime_t alarm = { 46 | .year = 2020, 47 | .month = 01, 48 | .day = 13, 49 | .dotw = 3, // 0 is Sunday, so 3 is Wednesday 50 | .hour = 11, 51 | .min = 20, 52 | .sec = 05 53 | }; 54 | 55 | rtc_set_alarm(&alarm, &alarm_callback); 56 | 57 | while(!fired); 58 | 59 | return 0; 60 | } -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 4 | following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following 7 | disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 16 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 | WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 21 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /usb/device/dev_hid_composite/usb_descriptors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifndef USB_DESCRIPTORS_H_ 26 | #define USB_DESCRIPTORS_H_ 27 | 28 | enum 29 | { 30 | REPORT_ID_KEYBOARD = 1, 31 | REPORT_ID_MOUSE, 32 | REPORT_ID_CONSUMER_CONTROL, 33 | REPORT_ID_GAMEPAD, 34 | REPORT_ID_COUNT 35 | }; 36 | 37 | #endif /* USB_DESCRIPTORS_H_ */ 38 | -------------------------------------------------------------------------------- /rtc/rtc_alarm_repeat/rtc_alarm_repeat.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include "hardware/rtc.h" 9 | #include "pico/stdlib.h" 10 | #include "pico/util/datetime.h" 11 | 12 | static volatile bool fired = false; 13 | 14 | static void alarm_callback(void) { 15 | datetime_t t = {0}; 16 | rtc_get_datetime(&t); 17 | char datetime_buf[256]; 18 | char *datetime_str = &datetime_buf[0]; 19 | datetime_to_str(datetime_str, sizeof(datetime_buf), &t); 20 | printf("Alarm Fired At %s\n", datetime_str); 21 | stdio_flush(); 22 | fired = true; 23 | } 24 | 25 | int main() { 26 | stdio_init_all(); 27 | printf("RTC Alarm Repeat!\n"); 28 | 29 | // Start on Wednesday 13th January 2021 11:20:00 30 | datetime_t t = { 31 | .year = 2020, 32 | .month = 01, 33 | .day = 13, 34 | .dotw = 3, // 0 is Sunday, so 3 is Wednesday 35 | .hour = 11, 36 | .min = 20, 37 | .sec = 00 38 | }; 39 | 40 | // Start the RTC 41 | rtc_init(); 42 | rtc_set_datetime(&t); 43 | 44 | // Alarm once a minute 45 | datetime_t alarm = { 46 | .year = -1, 47 | .month = -1, 48 | .day = -1, 49 | .dotw = -1, 50 | .hour = -1, 51 | .min = -1, 52 | .sec = 00 53 | }; 54 | 55 | rtc_set_alarm(&alarm, &alarm_callback); 56 | 57 | // Alarm will keep firing forever 58 | while(1); 59 | 60 | return 0; 61 | } -------------------------------------------------------------------------------- /pio/pwm/pwm.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | 9 | #include "pico/stdlib.h" 10 | #include "hardware/pio.h" 11 | #include "pwm.pio.h" 12 | 13 | // Write `period` to the input shift register 14 | void pio_pwm_set_period(PIO pio, uint sm, uint32_t period) { 15 | pio_sm_set_enabled(pio, sm, false); 16 | pio_sm_put_blocking(pio, sm, period); 17 | pio_sm_exec(pio, sm, pio_encode_pull(false, false)); 18 | pio_sm_exec(pio, sm, pio_encode_out(pio_isr, 32)); 19 | pio_sm_set_enabled(pio, sm, true); 20 | } 21 | 22 | // Write `level` to TX FIFO. State machine will copy this into X. 23 | void pio_pwm_set_level(PIO pio, uint sm, uint32_t level) { 24 | pio_sm_put_blocking(pio, sm, level); 25 | } 26 | 27 | int main() { 28 | stdio_init_all(); 29 | #ifndef PICO_DEFAULT_LED_PIN 30 | #warning pio/pwm example requires a board with a regular LED 31 | puts("Default LED pin was not defined"); 32 | #else 33 | 34 | // todo get free sm 35 | PIO pio = pio0; 36 | int sm = 0; 37 | uint offset = pio_add_program(pio, &pwm_program); 38 | printf("Loaded program at %d\n", offset); 39 | 40 | pwm_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN); 41 | pio_pwm_set_period(pio, sm, (1u << 16) - 1); 42 | 43 | int level = 0; 44 | while (true) { 45 | printf("Level = %d\n", level); 46 | pio_pwm_set_level(pio, sm, level * level); 47 | level = (level + 1) % 256; 48 | sleep_ms(10); 49 | } 50 | #endif 51 | } 52 | -------------------------------------------------------------------------------- /pio/ws2812/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_ws2812) 2 | 3 | # generate the header file into the source tree as it is included in the RP2040 datasheet 4 | pico_generate_pio_header(pio_ws2812 ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated) 5 | 6 | target_sources(pio_ws2812 PRIVATE ws2812.c) 7 | 8 | target_link_libraries(pio_ws2812 PRIVATE pico_stdlib hardware_pio) 9 | pico_add_extra_outputs(pio_ws2812) 10 | 11 | # add url via pico_set_program_url 12 | example_auto_set_url(pio_ws2812) 13 | 14 | add_executable(pio_ws2812_parallel) 15 | 16 | pico_generate_pio_header(pio_ws2812_parallel ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio OUTPUT_DIR ${CMAKE_CURRENT_LIST_DIR}/generated) 17 | 18 | target_sources(pio_ws2812_parallel PRIVATE ws2812_parallel.c) 19 | 20 | target_compile_definitions(pio_ws2812_parallel PRIVATE 21 | PIN_DBG1=3) 22 | 23 | target_link_libraries(pio_ws2812_parallel PRIVATE pico_stdlib hardware_pio hardware_dma) 24 | pico_add_extra_outputs(pio_ws2812_parallel) 25 | 26 | # add url via pico_set_program_url 27 | example_auto_set_url(pio_ws2812_parallel) 28 | 29 | # Additionally generate python and hex pioasm outputs for inclusion in the RP2040 datasheet 30 | add_custom_target(pio_ws2812_datasheet DEPENDS ${CMAKE_CURRENT_LIST_DIR}/generated/ws2812.py) 31 | add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/generated/ws2812.py 32 | DEPENDS ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio 33 | COMMAND Pioasm -o python ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio ${CMAKE_CURRENT_LIST_DIR}/generated/ws2812.py 34 | ) 35 | add_dependencies(pio_ws2812 pio_ws2812_datasheet) -------------------------------------------------------------------------------- /i2c/mma8451_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a MMA8451 3-axis digital accelerometer via I2C 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to the MMA8451 digital accelerometer sensor board. 4 | 5 | This example reads and displays the acceleration values of the board in the 3 axis. It also allows the user to set the trade-off between the range and precision based on the values they require. Values often have an offset which can be accounted for by writing to the offset correction registers. The datasheet for the sensor can be found at https://cdn-shop.adafruit.com/datasheets/MMA8451Q-1.pdf for additional information. 6 | 7 | == Wiring information 8 | 9 | Wiring up the device requires 4 jumpers, to connect VIN, GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the VSYS pin. 10 | 11 | 12 | 13 | [[mma8451_i2c_wiring]] 14 | [pdfwidth=75%] 15 | .Wiring Diagram for MMA8451. 16 | image::mma8451_i2c.png[] 17 | 18 | == List of Files 19 | 20 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 21 | mma8451_i2c.c:: The example code. 22 | 23 | == Bill of Materials 24 | 25 | .A list of materials required for the example 26 | [[mma8451-bom-table]] 27 | [cols=3] 28 | |=== 29 | | *Item* | *Quantity* | Details 30 | | Breadboard | 1 | generic part 31 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 32 | | MMA8451 board| 1 | https://www.adafruit.com/product/2019 33 | | M/M Jumper wires | 4 | generic part 34 | |=== 35 | 36 | 37 | -------------------------------------------------------------------------------- /pico_w/freertos/iperf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(picow_freertos_iperf_server_nosys 2 | picow_freertos_iperf.c 3 | ) 4 | target_compile_definitions(picow_freertos_iperf_server_nosys PRIVATE 5 | WIFI_SSID=\"${WIFI_SSID}\" 6 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 7 | ) 8 | target_include_directories(picow_freertos_iperf_server_nosys PRIVATE 9 | ${CMAKE_CURRENT_LIST_DIR} 10 | ${CMAKE_CURRENT_LIST_DIR}/../.. # for our common lwipopts 11 | ) 12 | target_link_libraries(picow_freertos_iperf_server_nosys 13 | pico_cyw43_arch_lwip_threadsafe_background 14 | pico_stdlib 15 | pico_lwip_iperf 16 | FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap 17 | ) 18 | pico_add_extra_outputs(picow_freertos_iperf_server_nosys) 19 | 20 | add_executable(picow_freertos_iperf_server_sys 21 | picow_freertos_iperf.c 22 | ) 23 | target_compile_definitions(picow_freertos_iperf_server_sys PRIVATE 24 | WIFI_SSID=\"${WIFI_SSID}\" 25 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 26 | NO_SYS=0 # don't want NO_SYS (generally this would be in your lwipopts.h) 27 | ) 28 | target_include_directories(picow_freertos_iperf_server_sys PRIVATE 29 | ${CMAKE_CURRENT_LIST_DIR} 30 | ${CMAKE_CURRENT_LIST_DIR}/../.. # for our common lwipopts 31 | ) 32 | target_link_libraries(picow_freertos_iperf_server_sys 33 | pico_cyw43_arch_lwip_sys_freertos 34 | pico_stdlib 35 | pico_lwip_iperf 36 | FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap 37 | ) 38 | pico_add_extra_outputs(picow_freertos_iperf_server_sys) 39 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | # Pull in SDK (must be before project) 4 | include(pico_sdk_import.cmake) 5 | 6 | project(pico_examples C CXX ASM) 7 | set(CMAKE_C_STANDARD 11) 8 | set(CMAKE_CXX_STANDARD 17) 9 | 10 | if (PICO_SDK_VERSION_STRING VERSION_LESS "1.3.0") 11 | message(FATAL_ERROR "Raspberry Pi Pico SDK version 1.3.0 (or later) required. Your version is ${PICO_SDK_VERSION_STRING}") 12 | endif() 13 | 14 | set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR}) 15 | 16 | # Initialize the SDK 17 | pico_sdk_init() 18 | 19 | include(example_auto_set_url.cmake) 20 | # Add blink example 21 | add_subdirectory(blink) 22 | 23 | # Add hello world example 24 | add_subdirectory(hello_world) 25 | 26 | add_compile_options(-Wall 27 | -Wno-format # int != int32_t as far as the compiler is concerned because gcc has int32_t as long int 28 | -Wno-unused-function # we have some for the docs that aren't called 29 | -Wno-maybe-uninitialized 30 | ) 31 | 32 | # Hardware-specific examples in subdirectories: 33 | add_subdirectory(adc) 34 | add_subdirectory(clocks) 35 | add_subdirectory(cmake) 36 | add_subdirectory(divider) 37 | add_subdirectory(dma) 38 | add_subdirectory(flash) 39 | add_subdirectory(gpio) 40 | add_subdirectory(i2c) 41 | add_subdirectory(interp) 42 | add_subdirectory(multicore) 43 | add_subdirectory(picoboard) 44 | add_subdirectory(pico_w) 45 | add_subdirectory(pio) 46 | add_subdirectory(pwm) 47 | add_subdirectory(reset) 48 | add_subdirectory(rtc) 49 | add_subdirectory(spi) 50 | add_subdirectory(system) 51 | add_subdirectory(timer) 52 | add_subdirectory(uart) 53 | add_subdirectory(usb) 54 | add_subdirectory(watchdog) 55 | -------------------------------------------------------------------------------- /pico_w/tcp_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT TEST_TCP_SERVER_IP) 2 | message("Skipping tcp_client example as TEST_TCP_SERVER_IP is not defined") 3 | else() 4 | add_executable(picow_tcpip_client_background 5 | picow_tcp_client.c 6 | ) 7 | target_compile_definitions(picow_tcpip_client_background PRIVATE 8 | WIFI_SSID=\"${WIFI_SSID}\" 9 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 10 | TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\" 11 | ) 12 | target_include_directories(picow_tcpip_client_background PRIVATE 13 | ${CMAKE_CURRENT_LIST_DIR} 14 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 15 | ) 16 | target_link_libraries(picow_tcpip_client_background 17 | pico_cyw43_arch_lwip_threadsafe_background 18 | pico_stdlib 19 | ) 20 | 21 | pico_add_extra_outputs(picow_tcpip_client_background) 22 | 23 | add_executable(picow_tcpip_client_poll 24 | picow_tcp_client.c 25 | ) 26 | target_compile_definitions(picow_tcpip_client_poll PRIVATE 27 | WIFI_SSID=\"${WIFI_SSID}\" 28 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 29 | TEST_TCP_SERVER_IP=\"${TEST_TCP_SERVER_IP}\" 30 | ) 31 | target_include_directories(picow_tcpip_client_poll PRIVATE 32 | ${CMAKE_CURRENT_LIST_DIR} 33 | ${CMAKE_CURRENT_LIST_DIR}/.. # for our common lwipopts 34 | ) 35 | target_link_libraries(picow_tcpip_client_poll 36 | pico_cyw43_arch_lwip_poll 37 | pico_stdlib 38 | ) 39 | pico_add_extra_outputs(picow_tcpip_client_poll) 40 | endif() 41 | -------------------------------------------------------------------------------- /gpio/hello_gpio_irq/hello_gpio_irq.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/gpio.h" 10 | 11 | static char event_str[128]; 12 | 13 | void gpio_event_string(char *buf, uint32_t events); 14 | 15 | void gpio_callback(uint gpio, uint32_t events) { 16 | // Put the GPIO event(s) that just happened into event_str 17 | // so we can print it 18 | gpio_event_string(event_str, events); 19 | printf("GPIO %d %s\n", gpio, event_str); 20 | } 21 | 22 | int main() { 23 | stdio_init_all(); 24 | 25 | printf("Hello GPIO IRQ\n"); 26 | gpio_set_irq_enabled_with_callback(2, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, &gpio_callback); 27 | 28 | // Wait forever 29 | while (1); 30 | 31 | return 0; 32 | } 33 | 34 | 35 | static const char *gpio_irq_str[] = { 36 | "LEVEL_LOW", // 0x1 37 | "LEVEL_HIGH", // 0x2 38 | "EDGE_FALL", // 0x4 39 | "EDGE_RISE" // 0x8 40 | }; 41 | 42 | void gpio_event_string(char *buf, uint32_t events) { 43 | for (uint i = 0; i < 4; i++) { 44 | uint mask = (1 << i); 45 | if (events & mask) { 46 | // Copy this event string into the user string 47 | const char *event_str = gpio_irq_str[i]; 48 | while (*event_str != '\0') { 49 | *buf++ = *event_str++; 50 | } 51 | events &= ~mask; 52 | 53 | // If more events add ", " 54 | if (events) { 55 | *buf++ = ','; 56 | *buf++ = ' '; 57 | } 58 | } 59 | } 60 | *buf++ = '\0'; 61 | } -------------------------------------------------------------------------------- /spi/max7219_8x7seg_spi/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a Max7219 driving an 8 digit 7 segment display via SPI 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to a Max7219 driving an 8 digit 7 segment display. The particular device used is interfaced via SPI at 3.3v. 4 | 5 | The Max7219 datasheet can be found here https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf 6 | 7 | 8 | == Wiring information 9 | 10 | Wiring up the device requires 5 jumpers as follows: 11 | 12 | * GPIO 17 (pin 22) Chip select -> CS on Max7219 board 13 | * GPIO 18 (pin 24) SCK/spi0_sclk -> CLK on Max7219 board 14 | * GPIO 19 (pin 25) MOSI/spi0_tx -> DIN on Max7219 board 15 | * 5v (pin 40) -> VCC on Max7219 board 16 | * GND (pin 38) -> GND on Max7219 board 17 | 18 | The example here uses SPI port 0. Power is supplied from the 5V pin. 19 | 20 | [NOTE] 21 | ====== 22 | There are many different manufacturers who sell boards with the Max7219. Whilst they all appear slightly different, they all have, at least, the same 5 pins required for power and communication. Please ensure you connect up as described in the previous paragraph. 23 | ====== 24 | 25 | == List of Files 26 | 27 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 28 | max7219_8x7seg_spi.c:: The example code. 29 | 30 | == Bill of Materials 31 | 32 | .A list of materials required for the example 33 | [[max7219-bom-table]] 34 | [cols=3] 35 | |=== 36 | | *Item* | *Quantity* | Details 37 | | Breadboard | 1 | generic part 38 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 39 | | max7219 board with 8x7segment LEDs| 1 | generic part 40 | | M/M Jumper wires | 5 | generic part 41 | |=== 42 | -------------------------------------------------------------------------------- /i2c/lcd_1602_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a 16x2 LCD via I2C 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to one of the very common 16x2 LCD character displays. The display will need a 3.3V I2C adapter board as this example uses I2C for communications. 4 | 5 | [NOTE] 6 | ====== 7 | These LCD displays can also be driven directly using GPIO without the use of an adapter board. That is beyond the scope of this example. 8 | ====== 9 | 10 | == Wiring information 11 | 12 | Wiring up the device requires 4 jumpers, to connect VCC (3.3v), GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the 3.3V pin. 13 | 14 | WARNING: Many displays of this type are 5v. If you wish to use a 5v display you will need to use level shifters on the SDA and SCL lines to convert from the 3.3V used by the RP2040. Whilst a 5v display will just about work at 3.3v, the display will be dim. 15 | 16 | 17 | [[lcd_1602_i2c_wiring]] 18 | [pdfwidth=75%] 19 | .Wiring Diagram for LCD1602A LCD with I2C bridge. 20 | image::lcd_1602_i2c_bb.png[] 21 | 22 | == List of Files 23 | 24 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 25 | lcd_1602_i2c.c:: The example code. 26 | 27 | == Bill of Materials 28 | 29 | .A list of materials required for the example 30 | [[lcd_1602_i2c-bom-table]] 31 | [cols=3] 32 | |=== 33 | | *Item* | *Quantity* | Details 34 | | Breadboard | 1 | generic part 35 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 36 | | 1602A based LCD panel 3.3v | 1 | generic part 37 | | 1602A to I2C bridge device 3.3v | 1 | generic part 38 | | M/M Jumper wires | 4 | generic part 39 | |=== 40 | -------------------------------------------------------------------------------- /gpio/hello_7segment/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a 7 segment LED via GPIO 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to a generic 7 segment LED device. It uses the LED to count from 0 to 9 and then repeat. If the button is pressed, then the numbers will count down instead of up. 4 | 5 | == Wiring information 6 | 7 | Our 7 Segment display has pins as follows. 8 | 9 | ---- 10 | --A-- 11 | F B 12 | --G-- 13 | E C 14 | --D-- 15 | ---- 16 | 17 | By default we are allocating GPIO 2 to segment A, 3 to B etc. 18 | So, connect GPIO 2 to pin A on the 7 segment LED display and so on. You will need the appropriate resistors (68 ohm should be fine) for each segment. 19 | The LED device used here is common anode, so the anode pin is connected to the 3.3v supply, and the GPIOs need to pull low (to ground) to complete the circuit. 20 | The pull direction of the GPIOs is specified in the code itself. 21 | 22 | Connect the switch to connect on pressing. One side should be connected to ground, the other to GPIO 9. 23 | 24 | 25 | [[hello_7segment_wiring]] 26 | [pdfwidth=75%] 27 | .Wiring Diagram for 7 segment LED. 28 | image::hello_7segment_bb.png[] 29 | 30 | == List of Files 31 | 32 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 33 | hello_7segment.c:: The example code. 34 | 35 | == Bill of Materials 36 | 37 | .A list of materials required for the example 38 | [[hello_7segment-bom-table]] 39 | [cols=3] 40 | |=== 41 | | *Item* | *Quantity* | Details 42 | | Breadboard | 1 | generic part 43 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 44 | | 7 segment LED module | 1 | generic part 45 | | 68 ohm resistor | 7 | generic part 46 | | DIL push to make switch | 1 | generic switch 47 | | M/M Jumper wires | 10 | generic part 48 | |=== 49 | -------------------------------------------------------------------------------- /dma/hello_dma/hello_dma.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // Use the DMA to copy data between two buffers in memory. 8 | 9 | #include 10 | #include "pico/stdlib.h" 11 | #include "hardware/dma.h" 12 | 13 | // Data will be copied from src to dst 14 | const char src[] = "Hello, world! (from DMA)"; 15 | char dst[count_of(src)]; 16 | 17 | int main() { 18 | stdio_init_all(); 19 | 20 | // Get a free channel, panic() if there are none 21 | int chan = dma_claim_unused_channel(true); 22 | 23 | // 8 bit transfers. Both read and write address increment after each 24 | // transfer (each pointing to a location in src or dst respectively). 25 | // No DREQ is selected, so the DMA transfers as fast as it can. 26 | 27 | dma_channel_config c = dma_channel_get_default_config(chan); 28 | channel_config_set_transfer_data_size(&c, DMA_SIZE_8); 29 | channel_config_set_read_increment(&c, true); 30 | channel_config_set_write_increment(&c, true); 31 | 32 | dma_channel_configure( 33 | chan, // Channel to be configured 34 | &c, // The configuration we just created 35 | dst, // The initial write address 36 | src, // The initial read address 37 | count_of(src), // Number of transfers; in this case each is 1 byte. 38 | true // Start immediately. 39 | ); 40 | 41 | // We could choose to go and do something else whilst the DMA is doing its 42 | // thing. In this case the processor has nothing else to do, so we just 43 | // wait for the DMA to finish. 44 | dma_channel_wait_for_finish_blocking(chan); 45 | 46 | // The DMA has now copied our text from the transmit buffer (src) to the 47 | // receive buffer (dst), so we can print it out from there. 48 | puts(dst); 49 | } 50 | -------------------------------------------------------------------------------- /flash/nuke/nuke.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | // Obliterate the contents of flash. This is a silly thing to do if you are 8 | // trying to run this program from flash, so you should really load and run 9 | // directly from SRAM. You can enable RAM-only builds for all targets by doing: 10 | // 11 | // cmake -DPICO_NO_FLASH=1 .. 12 | // 13 | // in your build directory. We've also forced no-flash builds for this app in 14 | // particular by adding: 15 | // 16 | // pico_set_binary_type(flash_nuke no_flash) 17 | // 18 | // To the CMakeLists.txt app for this file. Just to be sure, we can check the 19 | // define: 20 | #if !PICO_NO_FLASH 21 | #error "This example must be built to run from SRAM!" 22 | #endif 23 | 24 | #include "pico/stdlib.h" 25 | #include "hardware/flash.h" 26 | #include "pico/bootrom.h" 27 | 28 | int main() { 29 | uint flash_size_bytes; 30 | #ifndef PICO_FLASH_SIZE_BYTES 31 | #warning PICO_FLASH_SIZE_BYTES not set, assuming 16M 32 | flash_size_bytes = 16 * 1024 * 1024; 33 | #else 34 | flash_size_bytes = PICO_FLASH_SIZE_BYTES; 35 | #endif 36 | flash_range_erase(0, flash_size_bytes); 37 | // Leave an eyecatcher pattern in the first page of flash so picotool can 38 | // more easily check the size: 39 | static const uint8_t eyecatcher[FLASH_PAGE_SIZE] = "NUKE"; 40 | flash_range_program(0, eyecatcher, FLASH_PAGE_SIZE); 41 | 42 | #ifdef PICO_DEFAULT_LED_PIN 43 | // Flash LED for success 44 | gpio_init(PICO_DEFAULT_LED_PIN); 45 | gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); 46 | for (int i = 0; i < 3; ++i) { 47 | gpio_put(PICO_DEFAULT_LED_PIN, 1); 48 | sleep_ms(100); 49 | gpio_put(PICO_DEFAULT_LED_PIN, 0); 50 | sleep_ms(100); 51 | } 52 | #endif 53 | 54 | // Pop back up as an MSD drive 55 | reset_usb_boot(0, 0); 56 | } 57 | -------------------------------------------------------------------------------- /pio/squarewave/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pio_squarewave) 2 | 3 | pico_generate_pio_header(pio_squarewave ${CMAKE_CURRENT_LIST_DIR}/squarewave.pio) 4 | pico_generate_pio_header(pio_squarewave ${CMAKE_CURRENT_LIST_DIR}/squarewave_wrap.pio) 5 | pico_generate_pio_header(pio_squarewave ${CMAKE_CURRENT_LIST_DIR}/squarewave_fast.pio) 6 | 7 | target_sources(pio_squarewave PRIVATE squarewave.c) 8 | 9 | target_link_libraries(pio_squarewave PRIVATE pico_stdlib hardware_pio) 10 | pico_add_extra_outputs(pio_squarewave) 11 | 12 | # add url via pico_set_program_url 13 | example_auto_set_url(pio_squarewave) 14 | 15 | # generate .hex file and .pio.h file for the RP2040 datasheet (to make sure 16 | # the datasheet always shows the output of the latest pioasm version) 17 | add_custom_target(pio_squarewave_datasheet DEPENDS 18 | ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave.hex 19 | ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave.pio.h 20 | ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave_wrap.pio.h 21 | ) 22 | add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave.hex 23 | DEPENDS ${CMAKE_CURRENT_LIST_DIR}/squarewave.pio 24 | COMMAND Pioasm -o hex ${CMAKE_CURRENT_LIST_DIR}/squarewave.pio ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave.hex 25 | ) 26 | add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave.pio.h 27 | DEPENDS ${CMAKE_CURRENT_LIST_DIR}/squarewave.pio 28 | COMMAND Pioasm ${CMAKE_CURRENT_LIST_DIR}/squarewave.pio ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave.pio.h 29 | ) 30 | add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave_wrap.pio.h 31 | DEPENDS ${CMAKE_CURRENT_LIST_DIR}/squarewave_wrap.pio 32 | COMMAND Pioasm ${CMAKE_CURRENT_LIST_DIR}/squarewave_wrap.pio ${CMAKE_CURRENT_LIST_DIR}/generated/squarewave_wrap.pio.h 33 | ) 34 | add_dependencies(pio_squarewave pio_squarewave_datasheet) 35 | -------------------------------------------------------------------------------- /spi/max7219_32x8_spi/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a Max7219 driving an 32x8 LED display via SPI 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to a Max7219 driving an 32x8 LED display. The particular device used is interfaced via SPI at 3.3v. This PCB uses 4 Max7219 devices, each driving an 8x8 LED matrix, giving the total of 32x8. These devices are designed to be cascaded together in this way, and SPI commands are passed down the line of devices as required. 4 | 5 | The Max7219 datasheet can be found here https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf 6 | 7 | == Wiring information 8 | 9 | Wiring up the device requires 5 jumpers as follows: 10 | 11 | * GPIO 17 (pin 22) Chip select -> CS on Max7219 board 12 | * GPIO 18 (pin 24) SCK/spi0_sclk -> CLK on Max7219 board 13 | * GPIO 19 (pin 25) MOSI/spi0_tx -> DIN on Max7219 board 14 | * 5v (pin 40) -> VCC on Max7219 board 15 | * GND (pin 38) -> GND on Max7219 board 16 | 17 | The example here uses SPI port 0. Power is supplied from the 5V pin. 18 | 19 | [NOTE] 20 | ====== 21 | There are many different manufacturers who sell boards with the Max7219. Whilst they all appear slightly different, they all have, at least, the same 5 pins required for power and communication. Please ensure you connect up as described in the previous paragraph. 22 | ====== 23 | 24 | == List of Files 25 | 26 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 27 | max7219_32x8_spi.c:: The example code. 28 | 29 | == Bill of Materials 30 | 31 | .A list of materials required for the example 32 | [[max7219-bom-table]] 33 | [cols=3] 34 | |=== 35 | | *Item* | *Quantity* | Details 36 | | Breadboard | 1 | generic part 37 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 38 | | max7219 board with 4 8x8 LED matrices| 1 | generic part 39 | | M/M Jumper wires | 5 | generic part 40 | |=== 41 | -------------------------------------------------------------------------------- /adc/onboard_temperature/onboard_temperature.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | * 6 | */ 7 | 8 | #include 9 | #include "pico/stdlib.h" 10 | #include "hardware/adc.h" 11 | 12 | /* Choose 'C' for Celsius or 'F' for Fahrenheit. */ 13 | #define TEMPERATURE_UNITS 'C' 14 | 15 | /* References for this implementation: 16 | * raspberry-pi-pico-c-sdk.pdf, Section '4.1.1. hardware_adc' 17 | * pico-examples/adc/adc_console/adc_console.c */ 18 | float read_onboard_temperature(const char unit) { 19 | 20 | /* 12-bit conversion, assume max value == ADC_VREF == 3.3 V */ 21 | const float conversionFactor = 3.3f / (1 << 12); 22 | 23 | float adc = (float)adc_read() * conversionFactor; 24 | float tempC = 27.0f - (adc - 0.706f) / 0.001721f; 25 | 26 | if (unit == 'C') { 27 | return tempC; 28 | } else if (unit == 'F') { 29 | return tempC * 9 / 5 + 32; 30 | } 31 | 32 | return -1.0f; 33 | } 34 | 35 | int main() { 36 | stdio_init_all(); 37 | #ifdef PICO_DEFAULT_LED_PIN 38 | gpio_init(PICO_DEFAULT_LED_PIN); 39 | gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); 40 | #endif 41 | 42 | /* Initialize hardware AD converter, enable onboard temperature sensor and 43 | * select its channel (do this once for efficiency, but beware that this 44 | * is a global operation). */ 45 | adc_init(); 46 | adc_set_temp_sensor_enabled(true); 47 | adc_select_input(4); 48 | 49 | while (true) { 50 | float temperature = read_onboard_temperature(TEMPERATURE_UNITS); 51 | printf("Onboard temperature = %.02f %c\n", temperature, TEMPERATURE_UNITS); 52 | 53 | #ifdef PICO_DEFAULT_LED_PIN 54 | gpio_put(PICO_DEFAULT_LED_PIN, 1); 55 | sleep_ms(10); 56 | 57 | gpio_put(PICO_DEFAULT_LED_PIN, 0); 58 | #endif 59 | sleep_ms(990); 60 | } 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /pio/clocked_input/clocked_input.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2021 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program clocked_input 8 | 9 | ; Sample bits using an external clock, and push groups of bits into the RX FIFO. 10 | ; - IN pin 0 is the data pin 11 | ; - IN pin 1 is the clock pin 12 | ; - Autopush is enabled, threshold 8 13 | ; 14 | ; This program samples data with each rising clock edge (like mode 0 or mode 3 15 | ; SPI). The data is actually sampled one system clock cycle after the rising 16 | ; edge is observed, so a clock ratio of at least input_clk < clk_sys / 6 is 17 | ; recommended for good sampling alignment. 18 | 19 | wait 0 pin 1 20 | wait 1 pin 1 21 | in pins, 1 22 | 23 | % c-sdk { 24 | static inline void clocked_input_program_init(PIO pio, uint sm, uint offset, uint pin) { 25 | pio_sm_config c = clocked_input_program_get_default_config(offset); 26 | 27 | // Set the IN base pin to the provided `pin` parameter. This is the data 28 | // pin, and the next-numbered GPIO is used as the clock pin. 29 | sm_config_set_in_pins(&c, pin); 30 | // Set the pin directions to input at the PIO 31 | pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false); 32 | // Connect these GPIOs to this PIO block 33 | pio_gpio_init(pio, pin); 34 | pio_gpio_init(pio, pin + 1); 35 | 36 | // Shifting to left matches the customary MSB-first ordering of SPI. 37 | sm_config_set_in_shift( 38 | &c, 39 | false, // Shift-to-right = false (i.e. shift to left) 40 | true, // Autopush enabled 41 | 8 // Autopush threshold = 8 42 | ); 43 | 44 | // We only receive, so disable the TX FIFO to make the RX FIFO deeper. 45 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); 46 | 47 | // Load our configuration, and start the program from the beginning 48 | pio_sm_init(pio, sm, offset, &c); 49 | pio_sm_set_enabled(pio, sm, true); 50 | } 51 | %} 52 | -------------------------------------------------------------------------------- /flash/program/flash_program.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include "pico/stdlib.h" 11 | #include "hardware/flash.h" 12 | 13 | // We're going to erase and reprogram a region 256k from the start of flash. 14 | // Once done, we can access this at XIP_BASE + 256k. 15 | #define FLASH_TARGET_OFFSET (256 * 1024) 16 | 17 | const uint8_t *flash_target_contents = (const uint8_t *) (XIP_BASE + FLASH_TARGET_OFFSET); 18 | 19 | void print_buf(const uint8_t *buf, size_t len) { 20 | for (size_t i = 0; i < len; ++i) { 21 | printf("%02x", buf[i]); 22 | if (i % 16 == 15) 23 | printf("\n"); 24 | else 25 | printf(" "); 26 | } 27 | } 28 | 29 | int main() { 30 | stdio_init_all(); 31 | uint8_t random_data[FLASH_PAGE_SIZE]; 32 | for (int i = 0; i < FLASH_PAGE_SIZE; ++i) 33 | random_data[i] = rand() >> 16; 34 | 35 | printf("Generated random data:\n"); 36 | print_buf(random_data, FLASH_PAGE_SIZE); 37 | 38 | // Note that a whole number of sectors must be erased at a time. 39 | printf("\nErasing target region...\n"); 40 | flash_range_erase(FLASH_TARGET_OFFSET, FLASH_SECTOR_SIZE); 41 | printf("Done. Read back target region:\n"); 42 | print_buf(flash_target_contents, FLASH_PAGE_SIZE); 43 | 44 | printf("\nProgramming target region...\n"); 45 | flash_range_program(FLASH_TARGET_OFFSET, random_data, FLASH_PAGE_SIZE); 46 | printf("Done. Read back target region:\n"); 47 | print_buf(flash_target_contents, FLASH_PAGE_SIZE); 48 | 49 | bool mismatch = false; 50 | for (int i = 0; i < FLASH_PAGE_SIZE; ++i) { 51 | if (random_data[i] != flash_target_contents[i]) 52 | mismatch = true; 53 | } 54 | if (mismatch) 55 | printf("Programming failed!\n"); 56 | else 57 | printf("Programming successful!\n"); 58 | } 59 | -------------------------------------------------------------------------------- /i2c/mpu6050_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a MPU6050 accelerometer/gyroscope via I2C 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to the MPU6050 accelerometer/gyroscope board. This device uses I2C for communications, and most MPU6050 parts are happy running at either 3.3 or 5v. The Raspberry Pi RP2040 GPIO's work at 3.3v so that is what the example uses. 4 | 5 | [NOTE] 6 | ====== 7 | This is a very basic example, and only recovers raw data from the sensor. There are various calibration options available that should be used to ensure that the final results are accurate. It is also possible to wire up the interrupt pin to a GPIO and read data only when it is ready, rather than using the polling approach in the example. 8 | ====== 9 | 10 | == Wiring information 11 | 12 | Wiring up the device requires 4 jumpers, to connect VCC (3.3v), GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the 3.3V pin. 13 | 14 | [NOTE] 15 | ====== 16 | There are many different manufacturers who sell boards with the MPU6050. Whilst they all appear slightly different, they all have, at least, the same 4 pins required to power and communicate. When wiring up a board that is different to the one in the diagram, ensure you connect up as described in the previous paragraph. 17 | ====== 18 | 19 | 20 | [[mpu6050_i2c_wiring]] 21 | [pdfwidth=75%] 22 | .Wiring Diagram for MPU6050. 23 | image::mpu6050_i2c_bb.png[] 24 | 25 | == List of Files 26 | 27 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 28 | mpu6050_i2c.c:: The example code. 29 | 30 | == Bill of Materials 31 | 32 | .A list of materials required for the example 33 | [[mpu6050-bom-table]] 34 | [cols=3] 35 | |=== 36 | | *Item* | *Quantity* | Details 37 | | Breadboard | 1 | generic part 38 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 39 | | MPU6050 board| 1 | generic part 40 | | M/M Jumper wires | 4 | generic part 41 | |=== 42 | -------------------------------------------------------------------------------- /pio/apa102/apa102.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include "pico/stdlib.h" 11 | #include "hardware/pio.h" 12 | #include "apa102.pio.h" 13 | 14 | #define PIN_CLK 2 15 | #define PIN_DIN 3 16 | 17 | #define N_LEDS 150 18 | #define SERIAL_FREQ (5 * 1000 * 1000) 19 | 20 | // Global brightness value 0->31 21 | #define BRIGHTNESS 16 22 | 23 | void put_start_frame(PIO pio, uint sm) { 24 | pio_sm_put_blocking(pio, sm, 0u); 25 | } 26 | 27 | void put_end_frame(PIO pio, uint sm) { 28 | pio_sm_put_blocking(pio, sm, ~0u); 29 | } 30 | 31 | void put_rgb888(PIO pio, uint sm, uint8_t r, uint8_t g, uint8_t b) { 32 | pio_sm_put_blocking(pio, sm, 33 | 0x7 << 29 | // magic 34 | (BRIGHTNESS & 0x1f) << 24 | // global brightness parameter 35 | (uint32_t) b << 16 | 36 | (uint32_t) g << 8 | 37 | (uint32_t) r << 0 38 | ); 39 | } 40 | 41 | #define TABLE_SIZE (1 << 8) 42 | uint8_t wave_table[TABLE_SIZE]; 43 | 44 | int main() { 45 | stdio_init_all(); 46 | 47 | PIO pio = pio0; 48 | uint sm = 0; 49 | uint offset = pio_add_program(pio, &apa102_mini_program); 50 | apa102_mini_program_init(pio, sm, offset, SERIAL_FREQ, PIN_CLK, PIN_DIN); 51 | 52 | for (int i = 0; i < TABLE_SIZE; ++i) 53 | wave_table[i] = powf(sinf(i * M_PI / TABLE_SIZE), 5.f) * 255; 54 | 55 | uint t = 0; 56 | while (true) { 57 | put_start_frame(pio, sm); 58 | for (int i = 0; i < N_LEDS; ++i) { 59 | put_rgb888(pio, sm, 60 | wave_table[(i + t) % TABLE_SIZE], 61 | wave_table[(2 * i + 3 * 2) % TABLE_SIZE], 62 | wave_table[(3 * i + 4 * t) % TABLE_SIZE] 63 | ); 64 | } 65 | put_end_frame(pio, sm); 66 | sleep_ms(10); 67 | ++t; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /pico_w/access_point/dhcpserver/dhcpserver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the MicroPython project, http://micropython.org/ 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2018-2019 Damien P. George 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | #ifndef MICROPY_INCLUDED_LIB_NETUTILS_DHCPSERVER_H 27 | #define MICROPY_INCLUDED_LIB_NETUTILS_DHCPSERVER_H 28 | 29 | #include "lwip/ip_addr.h" 30 | 31 | #define DHCPS_BASE_IP (16) 32 | #define DHCPS_MAX_IP (8) 33 | 34 | typedef struct _dhcp_server_lease_t { 35 | uint8_t mac[6]; 36 | uint16_t expiry; 37 | } dhcp_server_lease_t; 38 | 39 | typedef struct _dhcp_server_t { 40 | ip_addr_t ip; 41 | ip_addr_t nm; 42 | dhcp_server_lease_t lease[DHCPS_MAX_IP]; 43 | struct udp_pcb *udp; 44 | } dhcp_server_t; 45 | 46 | void dhcp_server_init(dhcp_server_t *d, ip_addr_t *ip, ip_addr_t *nm); 47 | void dhcp_server_deinit(dhcp_server_t *d); 48 | 49 | #endif // MICROPY_INCLUDED_LIB_NETUTILS_DHCPSERVER_H 50 | -------------------------------------------------------------------------------- /timer/hello_timer/hello_timer.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 | 10 | /// \tag::timer_example[] 11 | volatile bool timer_fired = false; 12 | 13 | int64_t alarm_callback(alarm_id_t id, void *user_data) { 14 | printf("Timer %d fired!\n", (int) id); 15 | timer_fired = true; 16 | // Can return a value here in us to fire in the future 17 | return 0; 18 | } 19 | 20 | bool repeating_timer_callback(struct repeating_timer *t) { 21 | printf("Repeat at %lld\n", time_us_64()); 22 | return true; 23 | } 24 | 25 | int main() { 26 | stdio_init_all(); 27 | printf("Hello Timer!\n"); 28 | 29 | // Call alarm_callback in 2 seconds 30 | add_alarm_in_ms(2000, alarm_callback, NULL, false); 31 | 32 | // Wait for alarm callback to set timer_fired 33 | while (!timer_fired) { 34 | tight_loop_contents(); 35 | } 36 | 37 | // Create a repeating timer that calls repeating_timer_callback. 38 | // If the delay is > 0 then this is the delay between the previous callback ending and the next starting. 39 | // If the delay is negative (see below) then the next call to the callback will be exactly 500ms after the 40 | // start of the call to the last callback 41 | struct repeating_timer timer; 42 | add_repeating_timer_ms(500, repeating_timer_callback, NULL, &timer); 43 | sleep_ms(3000); 44 | bool cancelled = cancel_repeating_timer(&timer); 45 | printf("cancelled... %d\n", cancelled); 46 | sleep_ms(2000); 47 | 48 | // Negative delay so means we will call repeating_timer_callback, and call it again 49 | // 500ms later regardless of how long the callback took to execute 50 | add_repeating_timer_ms(-500, repeating_timer_callback, NULL, &timer); 51 | sleep_ms(3000); 52 | cancelled = cancel_repeating_timer(&timer); 53 | printf("cancelled... %d\n", cancelled); 54 | sleep_ms(2000); 55 | printf("Done\n"); 56 | return 0; 57 | } 58 | /// \end::timer_example[] 59 | -------------------------------------------------------------------------------- /pio/uart_rx/uart_rx.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | * 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | #include 8 | 9 | #include "pico/stdlib.h" 10 | #include "pico/multicore.h" 11 | #include "hardware/pio.h" 12 | #include "hardware/uart.h" 13 | #include "uart_rx.pio.h" 14 | 15 | // This program 16 | // - Uses UART1 (the spare UART, by default) to transmit some text 17 | // - Uses a PIO state machine to receive that text 18 | // - Prints out the received text to the default console (UART0) 19 | // This might require some reconfiguration on boards where UART1 is the 20 | // default UART. 21 | 22 | #define SERIAL_BAUD PICO_DEFAULT_UART_BAUD_RATE 23 | #define HARD_UART_INST uart1 24 | 25 | // You'll need a wire from GPIO4 -> GPIO3 26 | #define HARD_UART_TX_PIN 4 27 | #define PIO_RX_PIN 3 28 | 29 | // Ask core 1 to print a string, to make things easier on core 0 30 | void core1_main() { 31 | const char *s = (const char *) multicore_fifo_pop_blocking(); 32 | uart_puts(HARD_UART_INST, s); 33 | } 34 | 35 | int main() { 36 | // Console output (also a UART, yes it's confusing) 37 | setup_default_uart(); 38 | printf("Starting PIO UART RX example\n"); 39 | 40 | // Set up the hard UART we're going to use to print characters 41 | uart_init(HARD_UART_INST, SERIAL_BAUD); 42 | gpio_set_function(HARD_UART_TX_PIN, GPIO_FUNC_UART); 43 | 44 | // Set up the state machine we're going to use to receive them. 45 | PIO pio = pio0; 46 | uint sm = 0; 47 | uint offset = pio_add_program(pio, &uart_rx_program); 48 | uart_rx_program_init(pio, sm, offset, PIO_RX_PIN, SERIAL_BAUD); 49 | 50 | // Tell core 1 to print some text to uart1 as fast as it can 51 | multicore_launch_core1(core1_main); 52 | const char *text = "Hello, world from PIO! (Plus 2 UARTs and 2 cores, for complex reasons)\n"; 53 | multicore_fifo_push_blocking((uint32_t) text); 54 | 55 | // Echo characters received from PIO to the console 56 | while (true) { 57 | char c = uart_rx_program_getc(pio, sm); 58 | putchar(c); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pio/ir_nec/nec_transmit_library/nec_carrier_burst.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2021 mjcross 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | 8 | .program nec_carrier_burst 9 | 10 | ; Generate bursts of carrier. 11 | ; 12 | ; Repeatedly wait for an IRQ to be set then clear it and generate 21 cycles of 13 | ; carrier with 25% duty cycle 14 | ; 15 | .define NUM_CYCLES 21 ; how many carrier cycles to generate 16 | .define BURST_IRQ 7 ; which IRQ should trigger a carrier burst 17 | .define public TICKS_PER_LOOP 4 ; the number of instructions in the loop (for timing) 18 | 19 | .wrap_target 20 | set X, (NUM_CYCLES - 1) ; initialise the loop counter 21 | wait 1 irq BURST_IRQ ; wait for the IRQ then clear it 22 | cycle_loop: 23 | set pins, 1 ; set the pin high (1 cycle) 24 | set pins, 0 [1] ; set the pin low (2 cycles) 25 | jmp X--, cycle_loop ; (1 more cycle) 26 | .wrap 27 | 28 | 29 | % c-sdk { 30 | static inline void nec_carrier_burst_program_init(PIO pio, uint sm, uint offset, uint pin, float freq) { 31 | // Create a new state machine configuration 32 | // 33 | pio_sm_config c = nec_carrier_burst_program_get_default_config (offset); 34 | 35 | // Map the SET pin group to one pin, namely the `pin` 36 | // parameter to this function. 37 | // 38 | sm_config_set_set_pins (&c, pin, 1); 39 | 40 | // Set the GPIO function of the pin (connect the PIO to the pad) 41 | // 42 | pio_gpio_init (pio, pin); 43 | 44 | // Set the pin direction to output at the PIO 45 | // 46 | pio_sm_set_consecutive_pindirs (pio, sm, pin, 1, true); 47 | 48 | // Set the clock divider to generate the required frequency 49 | // 50 | float div = clock_get_hz (clk_sys) / (freq * nec_carrier_burst_TICKS_PER_LOOP); 51 | sm_config_set_clkdiv (&c, div); 52 | 53 | // Apply the configuration to the state machine 54 | // 55 | pio_sm_init (pio, sm, offset, &c); 56 | 57 | // Set the state machine running 58 | // 59 | pio_sm_set_enabled (pio, sm, true); 60 | } 61 | %} 62 | -------------------------------------------------------------------------------- /i2c/lis3dh_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a LIS3DH Nano Accelerometer via i2c. 2 | 3 | This example shows you how to interface the Raspberry Pi Pico to the LIS3DH accelerometer and temperature sensor. 4 | 5 | The code reads and displays the acceleration values of the board in the 3 axes and the ambient temperature value. The datasheet for the sensor can be found at https://www.st.com/resource/en/datasheet/cd00274221.pdf. The device is being operated on 'normal mode' and at a frequency of 1.344 kHz (this can be changed by editing the ODR bits of CTRL_REG4). The range of the data is controlled by the FS bit in CTRL_REG4 and is equal to ±2g in this example. The sensitivity depends on the operating mode and data range; exact values can be found on page 10 of the datasheet. In this case, the sensitivity value is 4mg (where g is the value of gravitational acceleration on the surface of Earth). In order to use the auxiliary ADC to read temperature, the we must set the BDU bit to 1 in CTRL_REG4 and the ADC_EN bit to 1 in TEMP_CFG_REG. Temperature is communicated through ADC 3. 6 | 7 | [NOTE] 8 | ===== 9 | The sensor doesn't have features to eliminate offsets in the data and these will need to be taken into account in the code. 10 | ===== 11 | 12 | == Wiring information 13 | 14 | Wiring up the device requires 4 jumpers, to connect VIN, GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the 3V pin. 15 | 16 | 17 | [[lis3dh_i2c_wiring]] 18 | [pdfwidth=75%] 19 | .Wiring Diagram for LIS3DH. 20 | image::lis3dh_i2c.png[] 21 | 22 | == List of Files 23 | 24 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 25 | lis3dh_i2c.c:: The example code. 26 | 27 | == Bill of Materials 28 | 29 | .A list of materials required for the example 30 | [[lis3dh-bom-table]] 31 | [cols=3] 32 | |=== 33 | | *Item* | *Quantity* | Details 34 | | Breadboard | 1 | generic part 35 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 36 | | LIS3DH board| 1 | https://www.adafruit.com/product/2809 37 | | M/M Jumper wires | 4 | generic part 38 | |=== 39 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Raspberry Pi Pico C/C++ Examples 2 | 3 | ## How to Report a Bug 4 | 5 | We use GitHub to host code, track [issues](https://github.com/raspberrypi/pico-examples/issues) and feature requests, and to accept [pull requests](https://github.com/raspberrypi/pico-examples/pulls). If you find think you have found a bug, please report it by [opening a new issue](https://github.com/raspberrypi/pico-examples/issues/new). Please include as much detail as possible, and ideally some code to reproduce the problem. 6 | 7 | ## How to Contribute Code 8 | 9 | In order to contribute new or updated code, you must first create a GitHub account and fork the original repository to your own account. You can make changes, save them in your repository, then [make a pull request](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) against this repository. The pull request will appear [in the repository](https://github.com/raspberrypi/pico-examples/pulls) where it can be assessed by the maintainers, and if appropriate, merged with the official repository. 10 | 11 | **NOTE:** Development takes place on the `develop` branch in this repository. Please open your https://github.com/raspberrypi/pico-examples/pulls[pull request] (PR) against the [`develop`](https://github.com/raspberrypi/pico-examples/tree/develop) branch, pull requests against the `master` branch will automatically CI fail checks and will not be accepted. You will be asked to rebase your PR against `develop` and if you do not do so, your PR will be closed. 12 | 13 | ### Code Style 14 | 15 | If you are contributing new or updated code please match the existing code style, particularly: 16 | 17 | * Use 4 spaces for indentation rather than tabs. 18 | * Braces are required for everything except single line `if` statements. 19 | * Opening braces should not be placed on a new line. 20 | 21 | ### Licensing 22 | 23 | Code in this repository is lisensed under the [BSD-3 License](LICENSE.TXT). By contributing content to this repository you are agreeing to place your contributions under this licence. 24 | -------------------------------------------------------------------------------- /pico_w/freertos/ping/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (EXISTS ${PICO_LWIP_CONTRIB_PATH}/apps/ping/ping.c) 2 | add_executable(picow_freertos_ping_nosys 3 | picow_freertos_ping.c 4 | ${PICO_LWIP_CONTRIB_PATH}/apps/ping/ping.c 5 | ) 6 | target_compile_definitions(picow_freertos_ping_nosys PRIVATE 7 | WIFI_SSID=\"${WIFI_SSID}\" 8 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 9 | ) 10 | target_include_directories(picow_freertos_ping_nosys PRIVATE 11 | ${CMAKE_CURRENT_LIST_DIR} 12 | ${CMAKE_CURRENT_LIST_DIR}/../.. # for our common lwipopts 13 | ${PICO_LWIP_CONTRIB_PATH}/apps/ping 14 | ) 15 | target_link_libraries(picow_freertos_ping_nosys 16 | pico_cyw43_arch_lwip_threadsafe_background 17 | pico_stdlib 18 | pico_lwip_iperf 19 | FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap 20 | ) 21 | pico_add_extra_outputs(picow_freertos_ping_nosys) 22 | 23 | add_executable(picow_freertos_ping_sys 24 | picow_freertos_ping.c 25 | ${PICO_LWIP_CONTRIB_PATH}/apps/ping/ping.c 26 | ) 27 | target_compile_definitions(picow_freertos_ping_sys PRIVATE 28 | WIFI_SSID=\"${WIFI_SSID}\" 29 | WIFI_PASSWORD=\"${WIFI_PASSWORD}\" 30 | NO_SYS=0 # don't want NO_SYS (generally this would be in your lwipopts.h) 31 | LWIP_SOCKET=1 # we need the socket API (generally this would be in your lwipopts.h) 32 | PING_USE_SOCKETS=1 33 | ) 34 | target_include_directories(picow_freertos_ping_sys PRIVATE 35 | ${CMAKE_CURRENT_LIST_DIR} 36 | ${CMAKE_CURRENT_LIST_DIR}/../.. # for our common lwipopts 37 | ${PICO_LWIP_CONTRIB_PATH}/apps/ping 38 | ) 39 | target_link_libraries(picow_freertos_ping_sys 40 | pico_cyw43_arch_lwip_sys_freertos 41 | pico_stdlib 42 | pico_lwip_iperf 43 | FreeRTOS-Kernel-Heap4 # FreeRTOS kernel and dynamic heap 44 | ) 45 | pico_add_extra_outputs(picow_freertos_ping_sys) 46 | endif() -------------------------------------------------------------------------------- /pio/st7789_lcd/st7789_lcd.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program st7789_lcd 8 | .side_set 1 9 | 10 | ; This is just a simple clocked serial TX. At 125 MHz system clock we can 11 | ; sustain up to 62.5 Mbps. 12 | ; Data on OUT pin 0 13 | ; Clock on side-set pin 0 14 | 15 | .wrap_target 16 | out pins, 1 side 0 ; stall here if no data (clock low) 17 | nop side 1 18 | .wrap 19 | 20 | % c-sdk { 21 | // For optimal use of DMA bandwidth we would use an autopull threshold of 32, 22 | // but we are using a threshold of 8 here (consume 1 byte from each FIFO entry 23 | // and discard the remainder) to make things easier for software on the other side 24 | 25 | static inline void st7789_lcd_program_init(PIO pio, uint sm, uint offset, uint data_pin, uint clk_pin, float clk_div) { 26 | pio_gpio_init(pio, data_pin); 27 | pio_gpio_init(pio, clk_pin); 28 | pio_sm_set_consecutive_pindirs(pio, sm, data_pin, 1, true); 29 | pio_sm_set_consecutive_pindirs(pio, sm, clk_pin, 1, true); 30 | pio_sm_config c = st7789_lcd_program_get_default_config(offset); 31 | sm_config_set_sideset_pins(&c, clk_pin); 32 | sm_config_set_out_pins(&c, data_pin, 1); 33 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); 34 | sm_config_set_clkdiv(&c, clk_div); 35 | sm_config_set_out_shift(&c, false, true, 8); 36 | pio_sm_init(pio, sm, offset, &c); 37 | pio_sm_set_enabled(pio, sm, true); 38 | } 39 | 40 | // Making use of the narrow store replication behaviour on RP2040 to get the 41 | // data left-justified (as we are using shift-to-left to get MSB-first serial) 42 | 43 | static inline void st7789_lcd_put(PIO pio, uint sm, uint8_t x) { 44 | while (pio_sm_is_tx_fifo_full(pio, sm)) 45 | ; 46 | *(volatile uint8_t*)&pio->txf[sm] = x; 47 | } 48 | 49 | // SM is done when it stalls on an empty FIFO 50 | 51 | static inline void st7789_lcd_wait_idle(PIO pio, uint sm) { 52 | uint32_t sm_stall_mask = 1u << (sm + PIO_FDEBUG_TXSTALL_LSB); 53 | pio->fdebug = sm_stall_mask; 54 | while (!(pio->fdebug & sm_stall_mask)) 55 | ; 56 | } 57 | %} 58 | -------------------------------------------------------------------------------- /spi/bme280_spi/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a BME280 temperature/humidity/pressure sensor via SPI 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to a BME280 temperature/humidity/pressure. The particular device used can be interfaced via I2C or SPI, we are using SPI, and interfacing at 3.3v. 4 | 5 | This examples reads the data from the sensor, and runs it through the appropriate compensation routines (see the chip datasheet for details https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf). At startup the compensation parameters required by the compensation routines are read from the chip. 6 | ) 7 | 8 | == Wiring information 9 | 10 | Wiring up the device requires 6 jumpers as follows: 11 | 12 | * GPIO 16 (pin 21) MISO/spi0_rx-> SDO/SDO on bme280 board 13 | * GPIO 17 (pin 22) Chip select -> CSB/!CS on bme280 board 14 | * GPIO 18 (pin 24) SCK/spi0_sclk -> SCL/SCK on bme280 board 15 | * GPIO 19 (pin 25) MOSI/spi0_tx -> SDA/SDI on bme280 board 16 | * 3.3v (pin 3;6) -> VCC on bme280 board 17 | * GND (pin 38) -> GND on bme280 board 18 | 19 | The example here uses SPI port 0. Power is supplied from the 3.3V pin. 20 | 21 | [NOTE] 22 | ====== 23 | There are many different manufacturers who sell boards with the BME280. Whilst they all appear slightly different, they all have, at least, the same 6 pins required to power and communicate. When wiring up a board that is different to the one in the diagram, ensure you connect up as described in the previous paragraph. 24 | ====== 25 | 26 | 27 | [[BME280_spi_wiring]] 28 | [pdfwidth=75%] 29 | .Wiring Diagram for bme280. 30 | image::bme280_spi_bb.png[] 31 | 32 | == List of Files 33 | 34 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 35 | bme280_spi.c:: The example code. 36 | 37 | == Bill of Materials 38 | 39 | .A list of materials required for the example 40 | [[BME280-bom-table]] 41 | [cols=3] 42 | |=== 43 | | *Item* | *Quantity* | Details 44 | | Breadboard | 1 | generic part 45 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 46 | | BME280 board| 1 | generic part 47 | | M/M Jumper wires | 6 | generic part 48 | |=== 49 | -------------------------------------------------------------------------------- /i2c/pa1010d_i2c/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a PA1010D Mini GPS module via I2C 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to the PA1010D Mini GPS module 4 | 5 | This allows you to read basic location and time data from the Recommended Minimum Specific GNSS Sentence (GNRMC protocol) and displays it in a user-friendly format. The datasheet for the module can be found on https://cdn-learn.adafruit.com/assets/assets/000/084/295/original/CD_PA1010D_Datasheet_v.03.pdf?1573833002. The output sentence is read and parsed to split the data fields into a 2D character array, which are then individually printed out. The commands to use different protocols and change settings are found on https://www.sparkfun.com/datasheets/GPS/Modules/PMTK_Protocol.pdf. Additional protocols can be used by editing the `init_command` array. 6 | 7 | [NOTE] 8 | ====== 9 | Each command requires a checksum after the asterisk. The checksum can be calculated for your command using the following website: https://nmeachecksum.eqth.net/. 10 | 11 | The GPS needs to be used outdoors in open skies and requires about 15 seconds to acquire a satellite signal in order to display valid data. When the signal is detected, the device will blink a green LED at 1 Hz. 12 | ====== 13 | 14 | 15 | == Wiring information 16 | 17 | Wiring up the device requires 4 jumpers, to connect VDD, GND, SDA and SCL. The example here uses I2C port 0, which is assigned to GPIO 4 (SDA) and 5 (SCL) in software. Power is supplied from the 3V pin. 18 | 19 | 20 | [[pa1010d_i2c_wiring]] 21 | [pdfwidth=75%] 22 | .Wiring Diagram for PA1010D. 23 | image::pa1010d_i2c.png[] 24 | 25 | == List of Files 26 | 27 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 28 | pa1010d_i2c.c:: The example code. 29 | 30 | == Bill of Materials 31 | 32 | .A list of materials required for the example 33 | [[pa1010d-bom-table]] 34 | [cols=3] 35 | |=== 36 | | *Item* | *Quantity* | Details 37 | | Breadboard | 1 | generic part 38 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 39 | | PA1010D board| 1 | https://shop.pimoroni.com/products/pa1010d-gps-breakout 40 | | M/M Jumper wires | 4 | generic part 41 | |=== 42 | 43 | -------------------------------------------------------------------------------- /pico_w/python_test_tcp/python_test_tcp_client.py: -------------------------------------------------------------------------------- 1 | import network 2 | import utime as time 3 | import usocket as socket 4 | 5 | # Set your wifi ssid and password here 6 | WIFI_SSID = const('') 7 | WIFI_PASSWORD = const('') 8 | 9 | # Set the server address here like 1.2.3.4 10 | SERVER_ADDR = const('') 11 | 12 | # These constants should match the server 13 | BUF_SIZE = const(2048) 14 | SERVER_PORT = const(4242) 15 | TEST_ITERATIONS = const(10) 16 | 17 | # Check if wifi details have been set 18 | if len(WIFI_SSID) == 0 or len(WIFI_PASSWORD) == 0: 19 | raise RuntimeError('set wifi ssid and password in this script') 20 | 21 | # Check server ip address set 22 | if len(SERVER_ADDR) == 0: 23 | raise RuntimeError('set the IP address of the server') 24 | 25 | # Start connection 26 | wlan = network.WLAN(network.STA_IF) 27 | wlan.active(True) 28 | wlan.connect(WIFI_SSID, WIFI_PASSWORD) 29 | 30 | # Wait for connect success or failure 31 | max_wait = 20 32 | while max_wait > 0: 33 | if wlan.status() < 0 or wlan.status() >= 3: 34 | break 35 | max_wait -= 1 36 | print('waiting for connection...') 37 | time.sleep(1) 38 | 39 | # Handle connection error 40 | if wlan.status() != 3: 41 | raise RuntimeError('wifi connection failed %d' % wlan.status()) 42 | else: 43 | print('connected') 44 | status = wlan.ifconfig() 45 | print( 'ip = ' + status[0] ) 46 | 47 | # Open socket to the server 48 | sock = socket.socket() 49 | addr = (SERVER_ADDR, SERVER_PORT) 50 | sock.connect(addr) 51 | 52 | # repeat test for a number of iterations 53 | for test_iteration in range(TEST_ITERATIONS): 54 | 55 | # Read BUF_SIZE bytes from the server 56 | read_buf = sock.read(BUF_SIZE) 57 | print('read %d bytes from server' % len(read_buf)) 58 | 59 | # Check size of data received 60 | if len(read_buf) != BUF_SIZE: 61 | raise RuntimeError('wrong amount of data read') 62 | 63 | # Send the data back to the server 64 | write_len = sock.write(read_buf) 65 | print('written %d bytes to server' % write_len) 66 | if write_len != BUF_SIZE: 67 | raise RuntimeError('wrong amount of data written') 68 | 69 | # All done 70 | sock.close() 71 | print("test completed") 72 | -------------------------------------------------------------------------------- /spi/mpu9250_spi/README.adoc: -------------------------------------------------------------------------------- 1 | = Attaching a MPU9250 accelerometer/gyroscope via SPI 2 | 3 | This example code shows how to interface the Raspberry Pi Pico to the MPU9250 accelerometer/gyroscope board. The particular device used can be interfaced via I2C or SPI, we are using SPI, and interfacing at 3.3v. 4 | 5 | [NOTE] 6 | ====== 7 | This is a very basic example, and only recovers raw data from the sensor. There are various calibration options available that should be used to ensure that the final results are accurate. It is also possible to wire up the interrupt pin to a GPIO and read data only when it is ready, rather than using the polling approach in the example. 8 | ====== 9 | 10 | == Wiring information 11 | 12 | Wiring up the device requires 6 jumpers as follows: 13 | 14 | * GPIO 4 (pin 6) MISO/spi0_rx-> ADO on MPU9250 board 15 | * GPIO 5 (pin 7) Chip select -> NCS on MPU9250 board 16 | * GPIO 6 (pin 9) SCK/spi0_sclk -> SCL on MPU9250 board 17 | * GPIO 7 (pin 10) MOSI/spi0_tx -> SDA on MPU9250 board 18 | * 3.3v (pin 36) -> VCC on MPU9250 board 19 | * GND (pin 38) -> GND on MPU9250 board 20 | 21 | The example here uses SPI port 0. Power is supplied from the 3.3V pin. 22 | 23 | [NOTE] 24 | ====== 25 | There are many different manufacturers who sell boards with the MPU9250. Whilst they all appear slightly different, they all have, at least, the same 6 pins required to power and communicate. When wiring up a board that is different to the one in the diagram, ensure you connect up as described in the previous paragraph. 26 | ====== 27 | 28 | 29 | [[mpu9250_spi_wiring]] 30 | [pdfwidth=75%] 31 | .Wiring Diagram for MPU9250. 32 | image::mpu9250_spi_bb.png[] 33 | 34 | == List of Files 35 | 36 | CMakeLists.txt:: CMake file to incorporate the example in to the examples build tree. 37 | mpu9250_spi.c:: The example code. 38 | 39 | == Bill of Materials 40 | 41 | .A list of materials required for the example 42 | [[MPU9250-bom-table]] 43 | [cols=3] 44 | |=== 45 | | *Item* | *Quantity* | Details 46 | | Breadboard | 1 | generic part 47 | | Raspberry Pi Pico | 1 | https://www.raspberrypi.com/products/raspberry-pi-pico/ 48 | | MPU9250 board| 1 | generic part 49 | | M/M Jumper wires | 6 | generic part 50 | |=== 51 | -------------------------------------------------------------------------------- /multicore/multicore_fifo_irqs/multicore_fifo_irqs.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 "pico/multicore.h" 10 | #include "hardware/irq.h" 11 | 12 | /// \tag::multicore_fifo_irqs[] 13 | 14 | #define FLAG_VALUE1 123 15 | #define FLAG_VALUE2 321 16 | 17 | static int core0_rx_val = 0, core1_rx_val = 0; 18 | 19 | void core0_sio_irq() { 20 | // Just record the latest entry 21 | while (multicore_fifo_rvalid()) 22 | core0_rx_val = multicore_fifo_pop_blocking(); 23 | 24 | multicore_fifo_clear_irq(); 25 | } 26 | 27 | void core1_sio_irq() { 28 | // Just record the latest entry 29 | while (multicore_fifo_rvalid()) 30 | core1_rx_val = multicore_fifo_pop_blocking(); 31 | 32 | multicore_fifo_clear_irq(); 33 | } 34 | 35 | void core1_entry() { 36 | multicore_fifo_clear_irq(); 37 | irq_set_exclusive_handler(SIO_IRQ_PROC1, core1_sio_irq); 38 | 39 | irq_set_enabled(SIO_IRQ_PROC1, true); 40 | 41 | // Send something to Core0, this should fire the interrupt. 42 | multicore_fifo_push_blocking(FLAG_VALUE1); 43 | 44 | while (1) 45 | tight_loop_contents(); 46 | } 47 | 48 | 49 | int main() { 50 | stdio_init_all(); 51 | printf("Hello, multicore_fifo_irqs!\n"); 52 | 53 | // We MUST start the other core before we enabled FIFO interrupts. 54 | // This is because the launch uses the FIFO's, enabling interrupts before 55 | // they are used for the launch will result in unexpected behaviour. 56 | multicore_launch_core1(core1_entry); 57 | 58 | irq_set_exclusive_handler(SIO_IRQ_PROC0, core0_sio_irq); 59 | irq_set_enabled(SIO_IRQ_PROC0, true); 60 | 61 | // Wait for a bit for things to happen 62 | sleep_ms(10); 63 | 64 | // Send something back to the other core 65 | multicore_fifo_push_blocking(FLAG_VALUE2); 66 | 67 | // Wait for a bit for things to happen 68 | sleep_ms(10); 69 | 70 | printf("Irq handlers should have rx'd some stuff - core 0 got %d, core 1 got %d!\n", core0_rx_val, core1_rx_val); 71 | 72 | while (1) 73 | tight_loop_contents(); 74 | } 75 | 76 | /// \end::multicore_fifo_irqs[] 77 | -------------------------------------------------------------------------------- /picoboard/blinky/blinky.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/gpio.h" 10 | 11 | const uint DOT_PERIOD_MS = 100; 12 | 13 | const char *morse_letters[] = { 14 | ".-", // A 15 | "-...", // B 16 | "-.-.", // C 17 | "-..", // D 18 | ".", // E 19 | "..-.", // F 20 | "--.", // G 21 | "....", // H 22 | "..", // I 23 | ".---", // J 24 | "-.-", // K 25 | ".-..", // L 26 | "--", // M 27 | "-.", // N 28 | "---", // O 29 | ".--.", // P 30 | "--.-", // Q 31 | ".-.", // R 32 | "...", // S 33 | "-", // T 34 | "..-", // U 35 | "...-", // V 36 | ".--", // W 37 | "-..-", // X 38 | "-.--", // Y 39 | "--.." // Z 40 | }; 41 | 42 | void put_morse_letter(uint led_pin, const char *pattern) { 43 | for (; *pattern; ++pattern) { 44 | gpio_put(led_pin, 1); 45 | if (*pattern == '.') 46 | sleep_ms(DOT_PERIOD_MS); 47 | else 48 | sleep_ms(DOT_PERIOD_MS * 3); 49 | gpio_put(led_pin, 0); 50 | sleep_ms(DOT_PERIOD_MS * 1); 51 | } 52 | sleep_ms(DOT_PERIOD_MS * 2); 53 | } 54 | 55 | void put_morse_str(uint led_pin, const char *str) { 56 | for (; *str; ++str) { 57 | if (*str >= 'A' && *str <= 'Z') { 58 | put_morse_letter(led_pin, morse_letters[*str - 'A']); 59 | } else if (*str >= 'a' && *str <= 'z') { 60 | put_morse_letter(led_pin, morse_letters[*str - 'a']); 61 | } else if (*str == ' ') { 62 | sleep_ms(DOT_PERIOD_MS * 4); 63 | } 64 | } 65 | } 66 | 67 | int main() { 68 | #ifndef PICO_DEFAULT_LED_PIN 69 | #warning picoboard/blinky example requires a board with a regular LED 70 | #else 71 | const uint LED_PIN = PICO_DEFAULT_LED_PIN; 72 | gpio_init(LED_PIN); 73 | gpio_set_dir(LED_PIN, GPIO_OUT); 74 | while (true) { 75 | put_morse_str(LED_PIN, "Hello world"); 76 | sleep_ms(1000); 77 | } 78 | #endif 79 | } 80 | -------------------------------------------------------------------------------- /timer/timer_lowlevel/timer_lowlevel.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/timer.h" 10 | #include "hardware/irq.h" 11 | 12 | /// \tag::get_time[] 13 | // Simplest form of getting 64 bit time from the timer. 14 | // It isn't safe when called from 2 cores because of the latching 15 | // so isn't implemented this way in the sdk 16 | static uint64_t get_time(void) { 17 | // Reading low latches the high value 18 | uint32_t lo = timer_hw->timelr; 19 | uint32_t hi = timer_hw->timehr; 20 | return ((uint64_t) hi << 32u) | lo; 21 | } 22 | /// \end::get_time[] 23 | 24 | /// \tag::alarm_standalone[] 25 | // Use alarm 0 26 | #define ALARM_NUM 0 27 | #define ALARM_IRQ TIMER_IRQ_0 28 | 29 | // Alarm interrupt handler 30 | static volatile bool alarm_fired; 31 | 32 | static void alarm_irq(void) { 33 | // Clear the alarm irq 34 | hw_clear_bits(&timer_hw->intr, 1u << ALARM_NUM); 35 | 36 | // Assume alarm 0 has fired 37 | printf("Alarm IRQ fired\n"); 38 | alarm_fired = true; 39 | } 40 | 41 | static void alarm_in_us(uint32_t delay_us) { 42 | // Enable the interrupt for our alarm (the timer outputs 4 alarm irqs) 43 | hw_set_bits(&timer_hw->inte, 1u << ALARM_NUM); 44 | // Set irq handler for alarm irq 45 | irq_set_exclusive_handler(ALARM_IRQ, alarm_irq); 46 | // Enable the alarm irq 47 | irq_set_enabled(ALARM_IRQ, true); 48 | // Enable interrupt in block and at processor 49 | 50 | // Alarm is only 32 bits so if trying to delay more 51 | // than that need to be careful and keep track of the upper 52 | // bits 53 | uint64_t target = timer_hw->timerawl + delay_us; 54 | 55 | // Write the lower 32 bits of the target time to the alarm which 56 | // will arm it 57 | timer_hw->alarm[ALARM_NUM] = (uint32_t) target; 58 | } 59 | 60 | int main() { 61 | stdio_init_all(); 62 | printf("Timer lowlevel!\n"); 63 | 64 | // Set alarm every 2 seconds 65 | while (1) { 66 | alarm_fired = false; 67 | alarm_in_us(1000000 * 2); 68 | // Wait for alarm to fire 69 | while (!alarm_fired); 70 | } 71 | } 72 | 73 | /// \end::alarm_standalone[] -------------------------------------------------------------------------------- /pio/uart_tx/uart_tx.pio: -------------------------------------------------------------------------------- 1 | ; 2 | ; Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 | ; 4 | ; SPDX-License-Identifier: BSD-3-Clause 5 | ; 6 | 7 | .program uart_tx 8 | .side_set 1 opt 9 | 10 | ; An 8n1 UART transmit program. 11 | ; OUT pin 0 and side-set pin 0 are both mapped to UART TX pin. 12 | 13 | pull side 1 [7] ; Assert stop bit, or stall with line in idle state 14 | set x, 7 side 0 [7] ; Preload bit counter, assert start bit for 8 clocks 15 | bitloop: ; This loop will run 8 times (8n1 UART) 16 | out pins, 1 ; Shift 1 bit from OSR to the first OUT pin 17 | jmp x-- bitloop [6] ; Each loop iteration is 8 cycles. 18 | 19 | 20 | % c-sdk { 21 | #include "hardware/clocks.h" 22 | 23 | static inline void uart_tx_program_init(PIO pio, uint sm, uint offset, uint pin_tx, uint baud) { 24 | // Tell PIO to initially drive output-high on the selected pin, then map PIO 25 | // onto that pin with the IO muxes. 26 | pio_sm_set_pins_with_mask(pio, sm, 1u << pin_tx, 1u << pin_tx); 27 | pio_sm_set_pindirs_with_mask(pio, sm, 1u << pin_tx, 1u << pin_tx); 28 | pio_gpio_init(pio, pin_tx); 29 | 30 | pio_sm_config c = uart_tx_program_get_default_config(offset); 31 | 32 | // OUT shifts to right, no autopull 33 | sm_config_set_out_shift(&c, true, false, 32); 34 | 35 | // We are mapping both OUT and side-set to the same pin, because sometimes 36 | // we need to assert user data onto the pin (with OUT) and sometimes 37 | // assert constant values (start/stop bit) 38 | sm_config_set_out_pins(&c, pin_tx, 1); 39 | sm_config_set_sideset_pins(&c, pin_tx); 40 | 41 | // We only need TX, so get an 8-deep FIFO! 42 | sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); 43 | 44 | // SM transmits 1 bit per 8 execution cycles. 45 | float div = (float)clock_get_hz(clk_sys) / (8 * baud); 46 | sm_config_set_clkdiv(&c, div); 47 | 48 | pio_sm_init(pio, sm, offset, &c); 49 | pio_sm_set_enabled(pio, sm, true); 50 | } 51 | 52 | static inline void uart_tx_program_putc(PIO pio, uint sm, char c) { 53 | pio_sm_put_blocking(pio, sm, (uint32_t)c); 54 | } 55 | 56 | static inline void uart_tx_program_puts(PIO pio, uint sm, const char *s) { 57 | while (*s) 58 | uart_tx_program_putc(pio, sm, *s++); 59 | } 60 | 61 | %} 62 | --------------------------------------------------------------------------------