Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ dkms.conf
build*/
doc/
Testing/

# Miscellaneous
*.log
*.tmp
.DS_Store
6 changes: 4 additions & 2 deletions doxygen/modules_diagram.dox.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ digraph modules {
Cond [label="Condition Variables", URL="\ref SystemSyncCond"];
WaitGroup [label="Wait Groups", URL="\ref SystemSyncWaitgroup"];
Atomic [label="Atomic Operations", URL="\ref SystemAtomic"];
Data [label="Data", URL="\ref SystemData"];
Data [label="Data", URL="\ref SystemData"];
DataRune [label="Runes", URL="\ref SystemDataRune"];
DataString [label="Strings", URL="\ref SystemDataString"];
DataScanner [label="Scanner", URL="\ref SystemDataScanner"];
Expand Down Expand Up @@ -53,8 +53,9 @@ digraph modules {
FT6236 [label="FT6236", URL="\ref FT6236"];
STMPE610 [label="STMPE610", URL="\ref STMPE610"];
ILI9341 [label="ILI9341", URL="\ref ILI9341"];
ST7701 [label="ST7701", URL="\ref ST7701"];
SDL [label="SDL", URL="\ref SDL"];
Pixels [label="Pixels", URL="\ref Pixel"];
Pixels [label="Pixels", URL="\ref Pixel"];
PixelDisplay [label="Display", URL="\ref PixelDisplay"];
PixelBitmap [label="Bitmap", URL="\ref PixelBitmap"];
Application [label="Application", URL="\ref Application"];
Expand Down Expand Up @@ -111,6 +112,7 @@ digraph modules {
Sensor -> BME680;
Display -> ILI9341;
Display -> SDL;
Display -> ST7701;
Pixels -> PixelDisplay;
Pixels -> PixelBitmap;
Application -> HID;
Expand Down
1 change: 1 addition & 0 deletions include/picofuse/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
#include "dev/ft6236.h"
#include "dev/ili9341.h"
#include "dev/sdl.h"
#include "dev/st7701.h"
#include "dev/stmpe610.h"
74 changes: 74 additions & 0 deletions include/picofuse/dev/st7701.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file st7701.h
* @brief ST7701 TFT LCD controller interface.
* @defgroup ST7701 ST7701
* @ingroup Display
*/
#pragma once

#include <picofuse/hw.h>
#include <picofuse/pix.h>
#include <stdbool.h>
#include <stdint.h>

///////////////////////////////////////////////////////////////////////////////
// TYPES

/**
* @brief Optional ST7701 initialization options.
* @ingroup ST7701
*/
typedef struct {
uint16_t rotation;
} dev_st7701_config_t;

///////////////////////////////////////////////////////////////////////////////
// LIFECYCLE

/** @name Lifecycle
* @{ */

/**
* @brief Fill an ST7701 config struct with safe defaults.
* @ingroup ST7701
* @param config Config structure to initialize.
*/
void dev_st7701_default_config(dev_st7701_config_t *config);

/**
* @brief Initialize an ST7701-driven display over SPI.
* @ingroup ST7701
* @param device SPI device handle. This panel has no D/CX GPIO - `device`
* must be a hw_spi_init() handle configured with `bits_per_word = 9`,
* command/data select packed as the 9th bit of every word (see
* hw_deviceio_xfr()).
* @param size Panel resolution.
* @param bl_pin Optional GPIO handle for the backlight. Pass `NULL` if
* the backlight isn't software-controlled.
* @param config Optional pointer to initialization options. Pass `NULL`
* to use default values.
* @return display handle, or `NULL` on failure
*/
pix_display_t *dev_st7701_init(hw_deviceio_t *device, pix_size_t size,
hw_gpio_t *bl_pin,
const dev_st7701_config_t *config);

/** @} */

///////////////////////////////////////////////////////////////////////////////
// METHODS

/** @name Methods
* @{ */

/**
* @brief Set the backlight brightness.
* @ingroup ST7701
* @param display Display handle from dev_st7701_init().
* @param brightness Brightness from `0` (off) to `255` (full).
* @return `false` if `display` wasn't created by dev_st7701_init(), or has
* no backlight pin.
*/
bool dev_st7701_set_backlight(pix_display_t *display, uint8_t brightness);

/** @} */
20 changes: 16 additions & 4 deletions include/picofuse/hw/deviceio.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,30 @@ hw_deviceio_bus_t hw_deviceio_bus(const hw_deviceio_t *device);
* @brief Perform a raw, bidirectional transfer.
* @ingroup DeviceIO
* @param device Device handle.
* @param data Buffer used for transmitted and received bytes.
* @param tx Number of bytes to transmit from `data`.
* @param rx Number of bytes to receive into `data + tx`.
* @param data Buffer used for transmitted and received words - `uint8_t*`
* unless noted otherwise below.
* @param tx Number of words to transmit from `data`.
* @param rx Number of words to receive into `data + tx * word_size`.
* @param timeout_ms Timeout in milliseconds for the operation. Set to `0`
* to use the backend's default transfer path.
* @return Number of bytes transferred, or `0` on failure.
* @return Number of words transferred, or `0` on failure.
*
* Supports write-only (`tx > 0, rx == 0`), read-only (`tx == 0, rx > 0`),
* and write-then-read (`tx > 0, rx > 0`) transfers. The exact semantics of
* a write-then-read - a repeated start on I2C, a continuous chip-select
* assertion on SPI - are defined by whichever bus `device` is actually
* bound to.
*
* A "word" here is 1 byte for every I2C device (no framing concept
* applies) and for an SPI device left at its default `hw_spi_config_t::
* bits_per_word` (8) - `data` is `uint8_t*`, and `tx`/`rx` count bytes
* exactly as before. For an SPI device configured with `bits_per_word`
* above 8 (9-16, e.g. a display panel that packs a command/data select
* bit as the 9th bit of every word), a word is 2 bytes instead - `data`
* must then be `uint16_t*`, and `tx`/`rx` count 16-bit words, not bytes
* (so the underlying buffer needs `(tx + rx) * 2` bytes of storage, not
Comment thread
djthorpe marked this conversation as resolved.
* `tx + rx`). Check whichever `hw_*_init()` built `device` for what its
* own word size is.
*/
size_t hw_deviceio_xfr(hw_deviceio_t *device, void *data, size_t tx, size_t rx,
uint32_t timeout_ms);
Expand Down
7 changes: 5 additions & 2 deletions include/picofuse/hw/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ typedef enum {
typedef struct {
bool cs_active_low; ///< True when chip-select is active low.
hw_spi_mode_t mode; ///< SPI mode selection.
uint8_t bits_per_word; ///< SPI frame size in bits.
uint8_t bits_per_word; ///< SPI frame size in bits (4-16). Above 8 changes
///< hw_deviceio_xfr()'s own word size for this
///< device - see its doc.
} hw_spi_config_t;

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -88,7 +90,8 @@ hw_deviceio_t *hw_spi_init_default(uint32_t baud_rate,
* @param index SPI adapter index to use.
* @param sck_pin GPIO handle for SCK.
* @param tx_pin GPIO handle for MOSI.
* @param rx_pin GPIO handle for MISO.
* @param rx_pin Optional GPIO handle for MISO. Pass `NULL` for a
* write-only device with no MISO line (e.g. a 3-wire display panel).
* @param cs_pin Optional GPIO handle for CS. Pass NULL to leave CS unmanaged.
* @param baud_rate Desired SPI clock rate in Hz.
* @param config Optional pointer to extended SPI configuration. Pass `NULL`
Expand Down
15 changes: 11 additions & 4 deletions src/picofuse/dev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

# SDL support
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
# SDL support - host-only. pkg-config always searches the host's own
# library paths regardless of cross-compilation, so on a Pico build this
# would otherwise "find" and try to link against the host's native SDL2
# (wrong ABI/arch entirely) - and SDL2 makes no sense on Pico anyway, with
# no windowing system to speak of.
if(NOT DEFINED PICO_BOARD)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
endif()
endif()
if(SDL2_FOUND)
message(STATUS "Found SDL2: enabling SDL display backend")
Expand All @@ -22,6 +28,7 @@ picofuse_library(
stmpe610/stmpe610.c
stmpe610/hid.c
${_sdl_src}
st7701/st7701.c
)

target_include_directories(picofuse-dev PRIVATE ${CMAKE_SOURCE_DIR}/include)
Expand Down
Binary file added src/picofuse/dev/st7701/ST7701.pdf
Binary file not shown.
Loading