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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

build
22 changes: 22 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"cmake.sourceDirectory": "/root/ws2812b/project/odroidc4",
"cmake.debugConfig": {
"cwd": "${workspaceFolder}",
"args": [
"-t", "write",
"--number", "24",
"--times", "100",
// "--color", "0",
"--color", "16711680", // red
// "--color", "65280", // green
// "--color", "255", // blue
],
},
"files.associations": {
"driver_ws2812b_basic.h": "c",
"spidev.h": "c",
"spi.h": "c",
"driver_ws2812b_interface.h": "c",
"stdlib.h": "c"
}
}
4 changes: 3 additions & 1 deletion example/driver_ws2812b_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ uint8_t ws2812b_basic_init(void)

/* link interface function */
DRIVER_WS2812B_LINK_INIT(&gs_handle, ws2812b_handle_t);
DRIVER_WS2812B_LINK_SPI_10MHZ_INIT(&gs_handle, ws2812b_interface_spi_10mhz_init);
DRIVER_WS2812B_LINK_SPI_INIT(&gs_handle, ws2812b_interface_spi_init);
DRIVER_WS2812B_LINK_SPI_DEINIT(&gs_handle, ws2812b_interface_spi_deinit);
DRIVER_WS2812B_LINK_SPI_WRITE_COMMAND(&gs_handle, ws2812b_interface_spi_write_cmd);
DRIVER_WS2812B_LINK_ONE_CODE(&gs_handle, ws2812b_interface_one_code);
DRIVER_WS2812B_LINK_ZERO_CODE(&gs_handle, ws2812b_interface_zero_code);
DRIVER_WS2812B_LINK_DELAY_MS(&gs_handle, ws2812b_interface_delay_ms);
DRIVER_WS2812B_LINK_DEBUG_PRINT(&gs_handle, ws2812b_interface_debug_print);

Expand Down
14 changes: 13 additions & 1 deletion interface/driver_ws2812b_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extern "C"{
* - 1 spi init 10mhz failed
* @note none
*/
uint8_t ws2812b_interface_spi_10mhz_init(void);
uint8_t ws2812b_interface_spi_init(void);

/**
* @brief interface spi bus deinit
Expand All @@ -68,6 +68,18 @@ uint8_t ws2812b_interface_spi_10mhz_init(void);
*/
uint8_t ws2812b_interface_spi_deinit(void);

/**
* @brief WS1812B One Code bit map
* @note Depends on SPI speed
*/
uint16_t ws2812b_interface_one_code(void);

/**
* @brief WS1812B Zero Code bit map
* @note Depends on SPI speed
*/
uint16_t ws2812b_interface_zero_code(void);

/**
* @brief interface spi bus write command
* @param[in] *buf points to a data buffer
Expand Down
24 changes: 21 additions & 3 deletions interface/driver_ws2812b_interface_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
#include "driver_ws2812b_interface.h"

/**
* @brief interface spi 10mhz bus init
* @brief interface spi bus init
* @return status code
* - 0 success
* - 1 spi init 10mhz failed
* - 1 spi init failed
* @note none
*/
uint8_t ws2812b_interface_spi_10mhz_init(void)
uint8_t ws2812b_interface_spi_init(void)
{
return 0;
}
Expand All @@ -60,6 +60,24 @@ uint8_t ws2812b_interface_spi_deinit(void)
return 0;
}

/**
* @brief WS1812B One Code bit map
* @note Depends on SPI speed
*/
uint16_t ws2812b_interface_one_code(void)
{
return 0xFF00U;
}

/**
* @brief WS1812B Zero Code bit map
* @note Depends on SPI speed
*/
uint16_t ws2812b_interface_zero_code(void)
{
return 0xF000U;
}

/**
* @brief interface spi bus write command
* @param[in] *buf points to a data buffer
Expand Down
212 changes: 212 additions & 0 deletions project/odroidc4/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#
# Copyright (c) 2015 - present LibDriver All rights reserved
#
# The MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

# set the cmake minimum version
cmake_minimum_required(VERSION 3.0)

# set the project name and language
project(ws2812b C)

# read the version from files
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cmake/VERSION ${CMAKE_PROJECT_NAME}_VERSION)

# set the project version
set(PROJECT_VERSION ${${CMAKE_PROJECT_NAME}_VERSION})

# set c standard c99
set(CMAKE_C_STANDARD 99)

# enable c standard required
set(CMAKE_C_STANDARD_REQUIRED True)

# set release level
# set(CMAKE_BUILD_TYPE Release)

# set the release flags of c
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")

# include cmake package config helpers
include(CMakePackageConfigHelpers)

# find the pkgconfig and use this tool to find the third party packages
find_package(PkgConfig REQUIRED)

# find the third party packages with pkgconfig
pkg_search_module(GPIOD REQUIRED libgpiod)

# include all library header directories
set(LIB_INC_DIRS
${GPIOD_INCLUDE_DIRS}
)

# include all linked libraries
set(LIBS
${GPIOD_LIBRARIES}
)

# include all header directories
set(INC_DIRS
${LIB_INC_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../../src
${CMAKE_CURRENT_SOURCE_DIR}/../../interface
${CMAKE_CURRENT_SOURCE_DIR}/../../example
${CMAKE_CURRENT_SOURCE_DIR}/../../test
${CMAKE_CURRENT_SOURCE_DIR}/interface/inc
)

# include all installed headers
file(GLOB INSTL_INCS
${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.h
)

# include all sources files
file(GLOB SRCS
${CMAKE_CURRENT_SOURCE_DIR}/../../src/*.c
)

# include executable source
file(GLOB MAIN
${SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/../../example/*.c
${CMAKE_CURRENT_SOURCE_DIR}/../../test/*.c
${CMAKE_CURRENT_SOURCE_DIR}/interface/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/driver/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
)

# enable output as a static library
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${SRCS})

# set the static library include directories
target_include_directories(${CMAKE_PROJECT_NAME}_static PRIVATE ${INC_DIRS})

# set the static library link libraries
target_link_libraries(${CMAKE_PROJECT_NAME}_static
m
)

# rename as ${CMAKE_PROJECT_NAME}
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# don't delete ${CMAKE_PROJECT_NAME} libs
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# set the static library version
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES VERSION ${${CMAKE_PROJECT_NAME}_VERSION})

# enable output as a dynamic library
add_library(${CMAKE_PROJECT_NAME} SHARED ${SRCS})

# set the executable program include directories
target_include_directories(${CMAKE_PROJECT_NAME}
PUBLIC $<INSTALL_INTERFACE:include/${CMAKE_PROJECT_NAME}>
PRIVATE ${INC_DIRS}
)

# set the dynamic library link libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
m
)

# rename as ${CMAKE_PROJECT_NAME}
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# don't delete ${CMAKE_PROJECT_NAME} libs
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# include the public header
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES PUBLIC_HEADER "${INSTL_INCS}")

# set the dynamic library version
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VERSION ${${CMAKE_PROJECT_NAME}_VERSION})

# enable the executable program
add_executable(${CMAKE_PROJECT_NAME}_exe ${MAIN})

# set the executable program include directories
target_include_directories(${CMAKE_PROJECT_NAME}_exe PRIVATE ${INC_DIRS})

# set the executable program link libraries
target_link_libraries(${CMAKE_PROJECT_NAME}_exe
${LIBS}
m
pthread
)

# rename as ${CMAKE_PROJECT_NAME}
set_target_properties(${CMAKE_PROJECT_NAME}_exe PROPERTIES OUTPUT_NAME ${CMAKE_PROJECT_NAME})

# don't delete ${CMAKE_PROJECT_NAME} exe
set_target_properties(${CMAKE_PROJECT_NAME}_exe PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# install the binary
install(TARGETS ${CMAKE_PROJECT_NAME}_exe
RUNTIME DESTINATION bin
)

# install the static library
install(TARGETS ${CMAKE_PROJECT_NAME}_static
ARCHIVE DESTINATION lib
)

# install the dynamic library
install(TARGETS ${CMAKE_PROJECT_NAME}
EXPORT ${CMAKE_PROJECT_NAME}-targets
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME}
)

# make the cmake config file
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake
INSTALL_DESTINATION cmake
)

# write the cmake config version
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config-version.cmake
VERSION ${PACKAGE_VERSION}
COMPATIBILITY AnyNewerVersion
)

# install the cmake files
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}-config-version.cmake"
DESTINATION cmake
)

# set the export items
install(EXPORT ${CMAKE_PROJECT_NAME}-targets
DESTINATION cmake
)

# add uninstall command
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake
)

#include ctest module
include(CTest)

# creat a test
add_test(NAME ${CMAKE_PROJECT_NAME}_test COMMAND ${CMAKE_PROJECT_NAME}_exe -p)
Binary file added project/odroidc4/J8Header.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading