-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from pimoroni/patch_plasma2040
Updates to Plasma 2040 C++ and MP examples
- Loading branch information
Showing
34 changed files
with
352 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include(analog.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
set(DRIVER_NAME analog) | ||
add_library(${DRIVER_NAME} INTERFACE) | ||
|
||
target_sources(${DRIVER_NAME} INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp | ||
) | ||
|
||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_adc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "analog.hpp" | ||
|
||
namespace pimoroni { | ||
uint16_t Analog::read_raw() { | ||
return adc_read(); | ||
} | ||
|
||
float Analog::read_voltage() { | ||
return ((float)adc_read() * 3.3f) / (1 << 12) / amplifier_gain; | ||
} | ||
|
||
float Analog::read_current() { | ||
if(resistor > 0.0f) | ||
return read_voltage() / resistor; | ||
else | ||
return read_voltage(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include "pico/stdlib.h" | ||
#include "hardware/adc.h" | ||
#include "common/pimoroni_common.hpp" | ||
|
||
namespace pimoroni { | ||
|
||
class Analog { | ||
public: | ||
Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f) : | ||
pin(pin), amplifier_gain(amplifier_gain), resistor(resistor) { | ||
adc_init(); | ||
|
||
//Make sure GPIO is high-impedance, no pullups etc | ||
adc_gpio_init(pin); | ||
|
||
//Select ADC input 0 (GPIO26) | ||
adc_select_input(pin - 26); | ||
}; | ||
uint16_t read_raw(); | ||
float read_voltage(); | ||
float read_current(); | ||
private: | ||
uint pin; | ||
float amplifier_gain; | ||
float resistor; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include(plasma.cmake) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
set(DRIVER_NAME plasma) | ||
add_library(${DRIVER_NAME} INTERFACE) | ||
|
||
target_sources(${DRIVER_NAME} INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/apa102.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/ws2812.cpp | ||
) | ||
|
||
target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
target_link_libraries(${DRIVER_NAME} INTERFACE | ||
pico_stdlib | ||
hardware_pio | ||
hardware_dma | ||
) | ||
|
||
pico_generate_pio_header(${DRIVER_NAME} ${CMAKE_CURRENT_LIST_DIR}/apa102.pio) | ||
pico_generate_pio_header(${DRIVER_NAME} ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set(OUTPUT_NAME plasma2040_rainbow) | ||
add_executable(${OUTPUT_NAME} plasma2040_rainbow.cpp) | ||
|
||
target_link_libraries(${OUTPUT_NAME} | ||
pico_stdlib | ||
plasma2040 | ||
rgbled | ||
button | ||
analog | ||
) | ||
|
||
# enable usb output | ||
pico_enable_stdio_usb(${OUTPUT_NAME} 1) | ||
|
||
pico_add_extra_outputs(${OUTPUT_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set(OUTPUT_NAME plasma2040_rotary) | ||
add_executable(${OUTPUT_NAME} plasma2040_rotary.cpp) | ||
|
||
target_link_libraries(${OUTPUT_NAME} | ||
pico_stdlib | ||
plasma2040 | ||
breakout_encoder | ||
pimoroni_i2c | ||
rgbled | ||
button | ||
) | ||
|
||
pico_add_extra_outputs(${OUTPUT_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
add_library(plasma2040 INTERFACE) | ||
|
||
target_sources(plasma2040 INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/apa102.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/ws2812.cpp | ||
) | ||
|
||
target_include_directories(plasma2040 INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
target_link_libraries(plasma2040 INTERFACE | ||
pico_stdlib | ||
hardware_pio | ||
hardware_dma | ||
) | ||
|
||
pico_generate_pio_header(plasma2040 ${CMAKE_CURRENT_LIST_DIR}/apa102.pio) | ||
pico_generate_pio_header(plasma2040 ${CMAKE_CURRENT_LIST_DIR}/ws2812.pio) | ||
# Pull in pico libraries that we need | ||
target_link_libraries(plasma2040 INTERFACE pico_stdlib plasma) |
Oops, something went wrong.