pkarashchenko commented on code in PR #6634: URL: https://github.com/apache/incubator-nuttx/pull/6634#discussion_r924195292
########## drivers/lcd/apa102.c: ########## @@ -0,0 +1,675 @@ +/**************************************************************************** + * drivers/lcd/apa102.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* Driver to create a display using RBG LEDs APA102 chained together */ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <stdint.h> +#include <stdbool.h> +#include <string.h> +#include <assert.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/arch.h> +#include <nuttx/spi/spi.h> +#include <nuttx/lcd/lcd.h> +#include <nuttx/lcd/apa102.h> +#include <nuttx/leds/apa102.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef MAX +# define MAX(a,b) ((a) > (b) ? (a) : (b)) +#endif + +/* Configuration ************************************************************/ + +/* APA102 Configuration Settings: + * + * CONFIG_APA102_XRES - Specifies the number of physical + * APA102 devices that are connected together horizontally. + * + * CONFIG_APA102_YRES - Specifies the number of physical + * APA102 devices that are connected together vertically. + * + * CONFIG_LCD_INTENSITY - Defines the default bright of LEDs. + * + * Required LCD driver settings: + * CONFIG_LCD_APA102 - Enable APA102 support + * + */ + +/* Verify that all configuration requirements have been met */ + +/* SPI frequency */ + +#ifndef CONFIG_APA102_FREQUENCY +# define CONFIG_APA102_FREQUENCY 10000000 +#endif + +/* APA102_COLUMNS determines the number of physical LEDs + * matrices that are used connected horizontally. + */ + +#ifndef CONFIG_APA102_XRES +# define CONFIG_APA102_XRES 16 +#endif + +/* APA102_LINES determines the number of physical LEDs + * matrices that are used connected vertically. + */ + +#ifndef CONFIG_APA102_YRES +# define CONFIG_APA102_YRES 16 +#endif + +/* Check contrast selection */ + +#if !defined(CONFIG_LCD_MAXCONTRAST) +# define CONFIG_LCD_MAXCONTRAST 1 +#endif + +/* Color Properties *********************************************************/ + +/* Display Resolution */ + +#define APA102_XRES CONFIG_APA102_XRES +#define APA102_YRES CONFIG_APA102_YRES + +/* Color depth and format */ + +#define APA102_BPP 16 +#define APA102_COLORFMT FB_FMT_RGB16_565 + +#define APA102_LUT_SIZE MAX(APA102_XRES, APA102_YRES) + +/* The size of the shadow frame buffer (4 bytes per LED) */ + +#define APA102_FBSIZE (APA102_XRES * APA102_YRES) + +/* LCD RGB Mapping */ + +#ifdef CONFIG_FB_CMAP +# error "RGB color mapping not supported by this driver" +#endif + +/* Cursor Controls */ + +#ifdef CONFIG_FB_HWCURSOR +# error "Cursor control not supported by this driver" +#endif + +/**************************************************************************** + * Private Type Definition + ****************************************************************************/ + +/* This structure describes the state of this driver */ + +struct apa102_dev_s +{ + /* Publicly visible device structure */ + + struct lcd_dev_s dev; + + /* Private LCD-specific information follows */ + + FAR struct spi_dev_s *spi; + uint8_t contrast; + uint8_t powered; + + /* We need to send all the APA102 matrix screen once. + * So, create a framebuffer to save it in memory + */ + + struct apa102_ledstrip_s fb[APA102_FBSIZE]; +}; + +/**************************************************************************** + * Private Function Protototypes + ****************************************************************************/ + +/* LCD Data Transfer Methods */ + +static int apa102_putrun(FAR struct lcd_dev_s *dev, fb_coord_t row, + fb_coord_t col, FAR const uint8_t *buffer, + size_t npixels); +static int apa102_getrun(FAR struct lcd_dev_s *dev, fb_coord_t row, + fb_coord_t col, FAR uint8_t *buffer, + size_t npixels); + +/* LCD Configuration */ + +static int apa102_getvideoinfo(FAR struct lcd_dev_s *dev, + FAR struct fb_videoinfo_s *vinfo); +static int apa102_getplaneinfo(FAR struct lcd_dev_s *dev, + unsigned int planeno, + FAR struct lcd_planeinfo_s *pinfo); + +/* LCD Specific Controls */ + +static int apa102_getpower(FAR struct lcd_dev_s *dev); +static int apa102_setpower(FAR struct lcd_dev_s *dev, int power); +static int apa102_getcontrast(FAR struct lcd_dev_s *dev); +static int apa102_setcontrast(FAR struct lcd_dev_s *dev, + unsigned int contrast); Review Comment: ```suggestion static int apa102_setcontrast(FAR struct lcd_dev_s *dev, unsigned int contrast); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org