2013-06-21 17:42:09 -06:00
|
|
|
/****************************************************************************
|
2021-03-08 18:39:04 -03:00
|
|
|
* boards/arm/sam34/sam4l-xplained/src/sam_slcd.c
|
2013-06-21 17:42:09 -06:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* 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
|
2013-06-21 17:42:09 -06:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-06-21 17:42:09 -06:00
|
|
|
*
|
2021-03-17 18:14:12 +01:00
|
|
|
* 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.
|
2013-06-21 17:42:09 -06:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* TODO: Add support for additional pixels: B0-B2, G0-G7, and E0-E7,
|
|
|
|
* probably via ioctl calls.
|
|
|
|
*/
|
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2023-02-01 10:41:12 -03:00
|
|
|
#include <sys/param.h>
|
2013-06-21 17:42:09 -06:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <poll.h>
|
2021-05-18 14:59:14 +08:00
|
|
|
#include <assert.h>
|
2013-06-21 17:42:09 -06:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/ascii.h>
|
|
|
|
#include <nuttx/streams.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/lcd/slcd_ioctl.h>
|
|
|
|
#include <nuttx/lcd/slcd_codec.h>
|
2020-02-01 15:17:32 +08:00
|
|
|
#include <nuttx/semaphore.h>
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2022-03-12 00:41:15 +08:00
|
|
|
#include "arm_internal.h"
|
2013-06-21 17:42:09 -06:00
|
|
|
#include "sam_gpio.h"
|
|
|
|
#include "sam4l_periphclks.h"
|
2019-05-25 07:37:39 -06:00
|
|
|
#include "hardware/sam4l_lcdca.h"
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
#include "sam4l-xplained.h"
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
#if defined(CONFIG_SAM34_LCDCA) && defined(CONFIG_SAM4L_XPLAINED_SLCD1MODULE)
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2019-08-15 16:19:17 +00:00
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
2021-08-01 15:27:08 +08:00
|
|
|
#ifndef CONFIG_LIBC_SLCDCODEC
|
|
|
|
# error This SLCD driver requires CONFIG_LIBC_SLCDCODEC
|
2013-06-21 17:42:09 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SAM34_OSC32K) && !defined(CONFIG_SAM34_RC32K)
|
|
|
|
# error This SLCD driver requires that either CONFIG_SAM34_OSC32K or
|
|
|
|
# error CONFIG_SAM34_RC32K be selected in the board configuration
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* LCD **********************************************************************/
|
2019-08-15 16:19:17 +00:00
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/* LCD characteristics. The logic in this driver is not portable; it is
|
|
|
|
* tailored for the SAM4l Xplained Pro's LED1 module. However, in an effort
|
|
|
|
* to add some reusability to this module, some of the tunable settings are
|
|
|
|
* included here as BOARD_ definitions (although they do not appear in the
|
|
|
|
* board.h header file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SLCD_NROWS 1
|
2013-06-22 10:39:25 -06:00
|
|
|
#define SLCD_NCHARS 5
|
2013-06-23 09:05:20 -06:00
|
|
|
#define SLCD_NBARS 4
|
2013-06-21 17:42:09 -06:00
|
|
|
#define SLCD_MAXCONTRAST 63
|
|
|
|
|
|
|
|
#define BOARD_SLCD_NCOM 4
|
2013-06-22 17:01:44 -06:00
|
|
|
#define BOARD_SLCD_NSEG 24
|
2013-06-21 17:42:09 -06:00
|
|
|
#define SLCD_NPINS (BOARD_SLCD_NCOM+BOARD_SLCD_NSEG+1)
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* An ASCII character may need to be decorated with a preceding decimal
|
|
|
|
* point
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SLCD_DP 0x01
|
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/* LCD controller bias configuration. */
|
|
|
|
|
|
|
|
#undef BOARD_XBIAS
|
|
|
|
#define BOARD_LPWAVE 1
|
|
|
|
|
|
|
|
/* LCD controller initial contrast setting. */
|
|
|
|
|
|
|
|
#define BOARD_INITIAL_CONTRAST (SLCD_MAXCONTRAST / 2)
|
|
|
|
|
|
|
|
/* LCD controller timing configuration */
|
|
|
|
|
|
|
|
#define BOARD_TIM_PRES 0 /* Clock prescaler {0|LCDCA_TIM_PRESC} */
|
|
|
|
#define BOARD_TIM_CLOCKDIV 8 /* Clock divider {1..8} */
|
|
|
|
#define BOARD_TIM_FC0 2 /* Frame 0 configuration {0..31} */
|
|
|
|
#define BOARD_TIM_FC1 2 /* Frame 1 configuration {0..31} */
|
|
|
|
#define BOARD_TIM_FC2 1 /* Frame 2 configuration {0..31} */
|
|
|
|
|
|
|
|
/* LCD controller configuration */
|
|
|
|
|
|
|
|
#if BOARD_SLCD_NCOM < 2
|
|
|
|
# define LCD_DUTY LCDCA_CFG_DUTY_STATIC /* Static COM0 */
|
|
|
|
#elif BOARD_SLCD_NCOM < 3
|
2013-06-22 10:39:25 -06:00
|
|
|
# define LCD_DUTY LCDCA_CFG_DUTY_1TO2 /* 1/2 COM[0:1] */
|
2013-06-21 17:42:09 -06:00
|
|
|
#elif BOARD_SLCD_NCOM < 4
|
|
|
|
# define LCD_DUTY LCDCA_CFG_DUTY_1TO3 /* 1/3 COM[0:2] */
|
|
|
|
#elif BOARD_SLCD_NCOM < 5
|
|
|
|
# define LCD_DUTY LCDCA_CFG_DUTY_1TO4 /* 1/4 COM[0:3] */
|
|
|
|
#else
|
|
|
|
# error Value of BOARD_SLCD_NCOM not supported
|
|
|
|
#endif
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* LCD Mapping
|
|
|
|
*
|
|
|
|
* a
|
|
|
|
* ---------
|
|
|
|
* |\ |h /|
|
|
|
|
* f| g | i |b
|
|
|
|
* | \ | / |
|
|
|
|
* --j-- --k-+
|
|
|
|
* | /| \ |
|
|
|
|
* e| l | n |c
|
|
|
|
* _ | / |m \| _
|
|
|
|
* B | | --------- | | B
|
|
|
|
* - d -
|
|
|
|
*
|
|
|
|
* ----- ---- ---- ---- ----- ----------------------------------------------
|
|
|
|
* COM0 COM1 COM2 COM3 Comments
|
|
|
|
* ----- ---- ---- ---- ----- ----------------------------------------------
|
|
|
|
* SEG0 G1 G2 G4 G3 Atmel logo, 4 stage battery-, Dot-point-,
|
|
|
|
* SEG1 G0 G6 G7 G5 usband play indicator
|
|
|
|
* SEG2 E7 E5 E3 E1 4 stage wireless-, AM-, PM- Volt- and milli
|
|
|
|
* SEG3 E6 E4 E2 E0 voltindicator
|
|
|
|
* SEG4 A0-h A0-i A0-k A0-n 1st 14-segment character
|
|
|
|
* SEG5 B3 A0-f A0-e A0-d
|
|
|
|
* SEG6 A0-a A0-b A0-c B4
|
|
|
|
* SEG7 A0-g A0-j A0-l A0-m
|
|
|
|
* SEG8 A1-h A1-i A1-k A1-n 2nd 14-segment character
|
|
|
|
* SEG9 B2 A1-f A1-e A1-d
|
|
|
|
* SEG10 A1-a A1-b A1-c B5
|
|
|
|
* SEG11 A1-g A1-j A1-l A1-m
|
|
|
|
* SEG12 A2-h A2-i A2-k A2-n 3rd 14-segment character
|
|
|
|
* SEG13 B1 A2-f A2-e A2-d
|
|
|
|
* SEG14 A2-a A2-b A2-c B6
|
|
|
|
* SEG15 A2-g A2-j A2-l A2-m
|
|
|
|
* SEG16 A3-h A3-i A3-k A3-n 4th 14-segment character
|
|
|
|
* SEG17 B0 A3-f A3-e A3-d
|
|
|
|
* SEG18 A3-a A3-b A3-c B7
|
|
|
|
* SEG19 A3-g A3-j A3-l A3-m
|
|
|
|
* SEG20 A4-h A4-i A4-k A4-n 5th 14-segment character. Celsius and
|
|
|
|
* SEG21 B8 A4-f A4-e A4-d Fahrenheit indicator
|
|
|
|
* SEG22 A4-a A4-b A4-c B9
|
|
|
|
* SEG23 A4-g A4-j A4-l A4-m
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SLCD_A0_STARTSEG 4
|
|
|
|
#define SLCD_A0_ENDSEG 7
|
|
|
|
#define SLCD_A1_STARTSEG 8
|
|
|
|
#define SLCD_A1_ENDSEG 11
|
|
|
|
#define SLCD_A2_STARTSEG 12
|
|
|
|
#define SLCD_A2_ENDSEG 15
|
|
|
|
#define SLCD_A3_STARTSEG 16
|
|
|
|
#define SLCD_A3_ENDSEG 19
|
|
|
|
#define SLCD_A4_STARTSEG 20
|
|
|
|
#define SLCD_A4_ENDSEG 23
|
|
|
|
|
|
|
|
#define SLCD_NB 10 /* Number of 'B' segments B0-B9 */
|
|
|
|
#define SLCD_NG 8 /* Number of 'G' segments G0-G7 */
|
|
|
|
#define SLCD_NE 8 /* Number of 'E' segments G0-G7 */
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
/* Named pixels */
|
|
|
|
|
|
|
|
#define SLCD_MINUS (&g_binfo[0])
|
|
|
|
#define SLCD_H (&g_binfo[1])
|
|
|
|
#define SLCD_M (&g_binfo[2])
|
|
|
|
#define SLCD_DP0 (&g_binfo[3])
|
|
|
|
#define SLCD_DP1 (&g_binfo[4])
|
|
|
|
#define SLCD_DP2 (&g_binfo[5])
|
|
|
|
#define SLCD_DP3 (&g_binfo[6])
|
|
|
|
#define SLCD_DP4 (&g_binfo[7])
|
|
|
|
#define SLCD_CENTIGRADE (&g_binfo[8])
|
|
|
|
#define SLCD_FAHRENHEIT (&g_binfo[9])
|
|
|
|
|
|
|
|
#define SLCD_ATMEL (&g_ginfo[0])
|
|
|
|
#define SLCD_BAR0 (&g_ginfo[1])
|
|
|
|
#define SLCD_BAR1 (&g_ginfo[2])
|
|
|
|
#define SLCD_BAR2 (&g_ginfo[3])
|
|
|
|
#define SLCD_BAR3 (&g_ginfo[4])
|
|
|
|
#define SLCD_COLON (&g_ginfo[5])
|
|
|
|
#define SLCD_USB (&g_ginfo[6])
|
|
|
|
#define SLCD_PAY (&g_ginfo[7])
|
|
|
|
|
|
|
|
#define SLCD_RNG0 (&g_einfo[0])
|
|
|
|
#define SLCD_RNG1 (&g_einfo[1])
|
|
|
|
#define SLCD_RNG2 (&g_einfo[2])
|
|
|
|
#define SLCD_RNG3 (&g_einfo[3])
|
|
|
|
#define SLCD_MV (&g_einfo[4])
|
|
|
|
#define SLCD_V (&g_einfo[5])
|
|
|
|
#define SLCD_PM (&g_einfo[6])
|
|
|
|
#define SLCD_AM (&g_einfo[7])
|
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Definition
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Global SLCD state */
|
|
|
|
|
|
|
|
struct sam_slcdstate_s
|
|
|
|
{
|
|
|
|
bool initialized; /* True: Completed initialization sequence */
|
|
|
|
uint8_t curpos; /* The current cursor position */
|
|
|
|
uint8_t buffer[SLCD_NCHARS]; /* SLCD ASCII content */
|
2013-06-22 10:39:25 -06:00
|
|
|
uint8_t options[SLCD_NCHARS]; /* Ornamentations */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Describes one pixel */
|
|
|
|
|
|
|
|
struct slcd_pixel_s
|
|
|
|
{
|
|
|
|
uint8_t segment;
|
|
|
|
uint8_t com;
|
2013-06-21 17:42:09 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Protototypes
|
|
|
|
****************************************************************************/
|
2019-08-15 16:19:17 +00:00
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/* Debug */
|
|
|
|
|
2016-06-15 11:40:33 -06:00
|
|
|
#ifdef CONFIG_DEBUG_LCD_INFO
|
2022-04-17 14:01:48 +08:00
|
|
|
static void slcd_dumpstate(const char *msg);
|
|
|
|
static void slcd_dumpslcd(const char *msg);
|
2013-06-21 17:42:09 -06:00
|
|
|
#else
|
|
|
|
# define slcd_dumpstate(msg)
|
|
|
|
# define slcd_dumpslcd(msg)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Internal utilities */
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
#if 0 /* Not used */
|
2013-06-21 17:42:09 -06:00
|
|
|
static void slcd_clear(void);
|
2013-06-22 10:39:25 -06:00
|
|
|
#endif
|
2022-04-17 14:01:48 +08:00
|
|
|
static void slcd_setpixel(const struct slcd_pixel_s *info);
|
|
|
|
static void slcd_clrpixel(const struct slcd_pixel_s *info);
|
2013-06-23 09:05:20 -06:00
|
|
|
static inline void slcd_setdp(uint8_t curpos);
|
|
|
|
static inline void slcd_clrdp(uint8_t curpos);
|
2013-06-21 17:42:09 -06:00
|
|
|
static uint8_t slcd_getcontrast(void);
|
2013-06-22 10:39:25 -06:00
|
|
|
static int slcd_setcontrast(unsigned int contrast);
|
2013-06-23 09:05:20 -06:00
|
|
|
static void slcd_writech(uint8_t ch, uint8_t curpos, uint8_t options);
|
2013-06-21 17:42:09 -06:00
|
|
|
static void slcd_action(enum slcdcode_e code, uint8_t count);
|
|
|
|
|
|
|
|
/* Character driver methods */
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static ssize_t slcd_read(struct file *, char *, size_t);
|
|
|
|
static ssize_t slcd_write(struct file *, const char *, size_t);
|
|
|
|
static int slcd_ioctl(struct file *filep, int cmd, unsigned long arg);
|
|
|
|
static int slcd_poll(struct file *filep, struct pollfd *fds,
|
2019-08-15 16:19:17 +00:00
|
|
|
bool setup);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* This is the driver state structure
|
|
|
|
* (there is no retained state information)
|
|
|
|
*/
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
static const struct file_operations g_slcdops =
|
|
|
|
{
|
2022-01-26 14:52:09 +02:00
|
|
|
NULL, /* open */
|
|
|
|
NULL, /* close */
|
2013-06-21 17:42:09 -06:00
|
|
|
slcd_read, /* read */
|
|
|
|
slcd_write, /* write */
|
2022-01-26 14:52:09 +02:00
|
|
|
NULL, /* seek */
|
2019-05-21 18:57:54 -06:00
|
|
|
slcd_ioctl, /* ioctl */
|
2023-01-02 17:02:51 +04:00
|
|
|
NULL, /* mmap */
|
2023-01-03 01:06:12 +08:00
|
|
|
NULL, /* truncate */
|
2019-05-21 18:57:54 -06:00
|
|
|
slcd_poll /* poll */
|
2013-06-21 17:42:09 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* LCD state data */
|
|
|
|
|
|
|
|
static struct sam_slcdstate_s g_slcdstate;
|
|
|
|
|
|
|
|
/* LCD pin configurations */
|
|
|
|
|
|
|
|
static gpio_pinset_t g_slcdgpio[SLCD_NPINS] =
|
|
|
|
{
|
|
|
|
GPIO_LCDCA_COM0, GPIO_LCDCA_COM1, GPIO_LCDCA_COM2, GPIO_LCDCA_COM3,
|
|
|
|
|
|
|
|
GPIO_LCDCA_SEG0, GPIO_LCDCA_SEG1, GPIO_LCDCA_SEG2, GPIO_LCDCA_SEG3,
|
|
|
|
GPIO_LCDCA_SEG4, GPIO_LCDCA_SEG5, GPIO_LCDCA_SEG6, GPIO_LCDCA_SEG7,
|
|
|
|
GPIO_LCDCA_SEG8, GPIO_LCDCA_SEG9, GPIO_LCDCA_SEG10, GPIO_LCDCA_SEG11,
|
|
|
|
GPIO_LCDCA_SEG12, GPIO_LCDCA_SEG13, GPIO_LCDCA_SEG14, GPIO_LCDCA_SEG15,
|
|
|
|
GPIO_LCDCA_SEG16, GPIO_LCDCA_SEG17, GPIO_LCDCA_SEG18, GPIO_LCDCA_SEG19,
|
|
|
|
GPIO_LCDCA_SEG20, GPIO_LCDCA_SEG21, GPIO_LCDCA_SEG22, GPIO_LCDCA_SEG23,
|
|
|
|
|
|
|
|
GPIO_LCD1_BL
|
|
|
|
};
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* First segment of each character */
|
|
|
|
|
|
|
|
static const uint8_t g_startseg[SLCD_NCHARS] =
|
|
|
|
{
|
|
|
|
SLCD_A0_STARTSEG, SLCD_A1_STARTSEG, SLCD_A2_STARTSEG, SLCD_A3_STARTSEG,
|
|
|
|
SLCD_A4_STARTSEG
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Pixel position for each 'B' segment */
|
|
|
|
|
|
|
|
static const struct slcd_pixel_s g_binfo[SLCD_NB] =
|
|
|
|
{
|
2021-03-18 09:57:48 +01:00
|
|
|
{17, 0},
|
|
|
|
{13, 0},
|
|
|
|
{9, 0},
|
|
|
|
{5, 0},
|
|
|
|
{6, 3},
|
|
|
|
{10, 3},
|
|
|
|
{14, 3},
|
|
|
|
{18, 3},
|
|
|
|
{21, 0},
|
|
|
|
{22, 3}
|
2013-06-22 10:39:25 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Pixel position for each 'G' segment */
|
|
|
|
|
|
|
|
static const struct slcd_pixel_s g_ginfo[SLCD_NG] =
|
|
|
|
{
|
2021-03-18 09:57:48 +01:00
|
|
|
{1, 0},
|
|
|
|
{0, 0},
|
|
|
|
{0, 1},
|
|
|
|
{0, 3},
|
|
|
|
{0, 2},
|
|
|
|
{1, 3},
|
|
|
|
{1, 1},
|
|
|
|
{1, 2}
|
2013-06-22 10:39:25 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Pixel position for each 'E' segment */
|
|
|
|
|
|
|
|
static const struct slcd_pixel_s g_einfo[SLCD_NE] =
|
|
|
|
{
|
2021-03-18 09:57:48 +01:00
|
|
|
{3, 3},
|
|
|
|
{2, 3},
|
|
|
|
{3, 2},
|
|
|
|
{2, 2},
|
|
|
|
{3, 1},
|
|
|
|
{2, 1},
|
|
|
|
{3, 0},
|
|
|
|
{2, 0}
|
2013-06-22 10:39:25 -06:00
|
|
|
};
|
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_dumpstate
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-15 11:40:33 -06:00
|
|
|
#ifdef CONFIG_DEBUG_LCD_INFO
|
2022-04-17 14:01:48 +08:00
|
|
|
static void slcd_dumpstate(const char *msg)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("%s:\n", msg);
|
|
|
|
lcdinfo(" curpos: %d\n",
|
2013-06-21 17:42:09 -06:00
|
|
|
g_slcdstate.curpos);
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo(" Display: [%c%c%c%c%c]\n",
|
2019-08-15 16:19:17 +00:00
|
|
|
g_slcdstate.buffer[0],
|
|
|
|
g_slcdstate.buffer[1],
|
|
|
|
g_slcdstate.buffer[2],
|
|
|
|
g_slcdstate.buffer[3],
|
|
|
|
g_slcdstate.buffer[4]);
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo(" Options: [%d%d%d%d%d]\n",
|
2019-08-15 16:19:17 +00:00
|
|
|
g_slcdstate.options[0],
|
|
|
|
g_slcdstate.options[1],
|
|
|
|
g_slcdstate.options[2],
|
|
|
|
g_slcdstate.options[3],
|
|
|
|
g_slcdstate.options[4]);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_dumpslcd
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-06-15 11:40:33 -06:00
|
|
|
#ifdef CONFIG_DEBUG_LCD_INFO
|
2022-04-17 14:01:48 +08:00
|
|
|
static void slcd_dumpslcd(const char *msg)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("%s:\n", msg);
|
|
|
|
lcdinfo(" CFG: %08x TIM: %08x SR: %08x\n",
|
2013-06-21 17:42:09 -06:00
|
|
|
getreg32(SAM_LCDCA_CFG), getreg32(SAM_LCDCA_TIM),
|
|
|
|
getreg32(SAM_LCDCA_SR));
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo(" DR0: %02x %08x DR1: %02x %08x\n",
|
2013-06-23 09:05:20 -06:00
|
|
|
getreg32(SAM_LCDCA_DRH0), getreg32(SAM_LCDCA_DRL0),
|
|
|
|
getreg32(SAM_LCDCA_DRH1), getreg32(SAM_LCDCA_DRL1));
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo(" DR2: %02x %08x DR3: %02x %08x\n",
|
2013-06-23 09:05:20 -06:00
|
|
|
getreg32(SAM_LCDCA_DRH2), getreg32(SAM_LCDCA_DRL2),
|
|
|
|
getreg32(SAM_LCDCA_DRH3), getreg32(SAM_LCDCA_DRL3));
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo(" BCFG: %08x CSRCFG: %08x CMCFG: %08x ACMCFG: %08x\n",
|
2013-06-21 17:42:09 -06:00
|
|
|
getreg32(SAM_LCDCA_BCFG), getreg32(SAM_LCDCA_CSRCFG),
|
|
|
|
getreg32(SAM_LCDCA_CMCFG), getreg32(SAM_LCDCA_ACMCFG));
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo(" ABMCFG: %08x IMR: %08x VER: %08x\n",
|
2013-06-21 17:42:09 -06:00
|
|
|
getreg32(SAM_LCDCA_ABMCFG), getreg32(SAM_LCDCA_IMR),
|
|
|
|
getreg32(SAM_LCDCA_VERSION));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_clear
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
#if 0 /* Not used */
|
2013-06-21 17:42:09 -06:00
|
|
|
static void slcd_clear(void)
|
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
linfo("Clearing\n");
|
2013-06-22 10:39:25 -06:00
|
|
|
|
|
|
|
/* Clear display memory */
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_CDM, SAM_LCDCA_CR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_setpixel
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static void slcd_setpixel(const struct slcd_pixel_s *info)
|
2013-06-22 10:39:25 -06:00
|
|
|
{
|
|
|
|
uintptr_t regaddr;
|
|
|
|
uint32_t regval;
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
regaddr = SAM_LCDCA_DRL(info->com);
|
2013-06-22 10:39:25 -06:00
|
|
|
regval = getreg32(regaddr);
|
|
|
|
regval |= (1 << info->segment);
|
|
|
|
putreg32(regval, regaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_clrpixel
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static void slcd_clrpixel(const struct slcd_pixel_s *info)
|
2013-06-22 10:39:25 -06:00
|
|
|
{
|
|
|
|
uintptr_t regaddr;
|
|
|
|
uint32_t regval;
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
regaddr = SAM_LCDCA_DRL(info->com);
|
2013-06-22 10:39:25 -06:00
|
|
|
regval = getreg32(regaddr);
|
|
|
|
regval &= ~(1 << info->segment);
|
|
|
|
putreg32(regval, regaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_setdp
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
static inline void slcd_setdp(uint8_t curpos)
|
2013-06-22 10:39:25 -06:00
|
|
|
{
|
|
|
|
/* Set the decimal point before the current cursor position
|
|
|
|
*
|
|
|
|
* B3 B4 B5 B6 B7
|
|
|
|
* .O .O .O .O .O
|
|
|
|
*/
|
|
|
|
|
|
|
|
slcd_setpixel(&g_binfo[curpos + 3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_clrdp
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
static inline void slcd_clrdp(uint8_t curpos)
|
2013-06-22 10:39:25 -06:00
|
|
|
{
|
|
|
|
/* Set the decimal point before the current cursor position
|
|
|
|
*
|
|
|
|
* B3 B4 B5 B6 B7
|
|
|
|
* .O .O .O .O .O
|
|
|
|
*/
|
|
|
|
|
|
|
|
slcd_clrpixel(&g_binfo[curpos + 3]);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_getcontrast
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static uint8_t slcd_getcontrast(void)
|
|
|
|
{
|
|
|
|
uint32_t regval;
|
|
|
|
uint32_t ucontrast;
|
|
|
|
int32_t scontrast;
|
|
|
|
|
2020-02-23 16:50:23 +08:00
|
|
|
/* Get the current contrast value */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
regval = getreg32(SAM_LCDCA_CFG);
|
2013-06-22 10:39:25 -06:00
|
|
|
ucontrast = (regval & LCDCA_CFG_FCST_MASK) >> LCDCA_CFG_FCST_SHIFT;
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/* Sign extend and translate the 6 bit signed value
|
|
|
|
*
|
|
|
|
* Unsigned Signed Extended Translated
|
|
|
|
* Value Hex Dec
|
|
|
|
* ---------- --------- ----- -----------
|
|
|
|
* 0000 001f 0000 001f 31 63
|
|
|
|
* 0000 0000 0000 0000 0 32
|
|
|
|
* 0000 0020 ffff ffe0 -32 0
|
|
|
|
*/
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
scontrast = (int32_t)(ucontrast << (32 - 6));
|
2013-06-21 17:42:09 -06:00
|
|
|
scontrast >>= (32 - 6);
|
|
|
|
return scontrast + 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_setcontrast
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int slcd_setcontrast(unsigned int contrast)
|
|
|
|
{
|
|
|
|
uint32_t regval;
|
|
|
|
int scontrast;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
/* Make sure that the contrast setting is within range */
|
|
|
|
|
|
|
|
if (contrast > SLCD_MAXCONTRAST)
|
|
|
|
{
|
|
|
|
contrast = SLCD_MAXCONTRAST;
|
|
|
|
ret = -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Translate to get a signed value:
|
|
|
|
*
|
|
|
|
* Input Translated Value Masked Value
|
|
|
|
* Dec Hex
|
|
|
|
* ------ --- ------------ -----------
|
|
|
|
* 63 -> 31 0000 0001f 0000 0001f
|
|
|
|
* 32 -> 0 0000 00000 0000 00000
|
|
|
|
* 0 -> -32 ffff fffe0 0000 00020
|
|
|
|
*/
|
|
|
|
|
|
|
|
scontrast = (int)contrast - 32;
|
|
|
|
|
2020-02-23 16:50:23 +08:00
|
|
|
/* Set the new contrast value */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
regval = getreg32(SAM_LCDCA_CFG);
|
|
|
|
regval &= ~LCDCA_CFG_FCST_MASK;
|
|
|
|
regval |= LCDCA_CFG_FCST(scontrast);
|
|
|
|
putreg32(regval, SAM_LCDCA_CFG);
|
|
|
|
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("contrast: %d CFG: %08x\n", contrast, getreg32(SAM_LCDCA_CFG));
|
2013-06-21 17:42:09 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_writech
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
static void slcd_writech(uint8_t ch, uint8_t curpos, uint8_t options)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
uint8_t segment;
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* "LCDCA handles up to four ASCII characters tables, configured in
|
|
|
|
* Character Mapping Configuration register (CMCFG). Instead of handling
|
|
|
|
* each segments in display memory for a selected digit, user writes ASCII
|
|
|
|
* code in Character Mapping Control Register (CMCR) to display the
|
|
|
|
* corresponding character.
|
|
|
|
*
|
|
|
|
* "User can then drive several digits with few operations:
|
|
|
|
*
|
|
|
|
* "1. Select the Type of Digit (CMCFG.TDG),
|
|
|
|
* "2. Write the Start Segment value (CMCFG.STSEG) of the first digit,
|
|
|
|
* "3. Select Digit Reverse Mode (CMCFG.DREV) if required. If DREV is one,
|
|
|
|
* segment index is decremented,
|
|
|
|
* "4. Then write ASCII code in CMCR register."
|
|
|
|
*/
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
segment = g_startseg[curpos];
|
2019-08-15 16:19:17 +00:00
|
|
|
putreg32(LCDCA_CMCFG_TDG_14S4C | LCDCA_CMCFG_STSEG(segment),
|
|
|
|
SAM_LCDCA_CMCFG);
|
2013-06-22 10:39:25 -06:00
|
|
|
putreg32(ch, SAM_LCDCA_CMDR);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
/* Check if we need to decorate the character with a preceding dot. */
|
|
|
|
|
|
|
|
if ((options & SLCD_DP) != 0)
|
|
|
|
{
|
|
|
|
slcd_setdp(curpos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slcd_clrdp(curpos);
|
|
|
|
}
|
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/* Save these values in the state structure */
|
|
|
|
|
|
|
|
g_slcdstate.buffer[curpos] = ch;
|
2013-06-23 09:05:20 -06:00
|
|
|
g_slcdstate.options[curpos] = options;
|
2013-06-21 17:42:09 -06:00
|
|
|
slcd_dumpstate("AFTER WRITE");
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_action
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void slcd_action(enum slcdcode_e code, uint8_t count)
|
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("Action: %d count: %d\n", code, count);
|
2013-06-21 17:42:09 -06:00
|
|
|
slcd_dumpstate("BEFORE ACTION");
|
|
|
|
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
/* Erasure */
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
case SLCDCODE_BACKDEL: /* Backspace (backward delete) N characters */
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* If we are at the home position or if the count is zero,
|
|
|
|
* then ignore the action
|
|
|
|
*/
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
if (g_slcdstate.curpos < 1 || count < 1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* Otherwise, BACKDEL is like moving the cursor back N characters
|
|
|
|
* then doing a forward deletion.
|
|
|
|
* Decrement the cursor position and fall through.
|
2013-06-21 17:42:09 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = (int)g_slcdstate.curpos - count;
|
|
|
|
if (tmp < 0)
|
|
|
|
{
|
|
|
|
tmp = 0;
|
|
|
|
count = g_slcdstate.curpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the updated cursor positions */
|
|
|
|
|
|
|
|
g_slcdstate.curpos = tmp;
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
case SLCDCODE_FWDDEL: /* DELete (forward delete) N characters moving text */
|
2013-06-21 17:42:09 -06:00
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
int nchars;
|
|
|
|
int nmove;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* How many characters are to the right of the cursor position
|
|
|
|
* (including the one at the cursor position)? Then get the
|
|
|
|
* number of characters to move.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nchars = SLCD_NCHARS - g_slcdstate.curpos;
|
|
|
|
nmove = MIN(nchars, count) - 1;
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
/* Move all characters after the current cursor position left by
|
|
|
|
* 'nmove' characters
|
|
|
|
*/
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
for (i = g_slcdstate.curpos + nmove; i < SLCD_NCHARS - 1; i++)
|
|
|
|
{
|
2019-08-15 16:19:17 +00:00
|
|
|
slcd_writech(g_slcdstate.buffer[i - nmove], i,
|
|
|
|
g_slcdstate.options[i - nmove]);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Erase the last 'nmove' characters on the display */
|
|
|
|
|
|
|
|
for (i = SLCD_NCHARS - nmove; i < SLCD_NCHARS; i++)
|
|
|
|
{
|
2013-06-23 09:05:20 -06:00
|
|
|
slcd_writech(' ', i, 0);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
case SLCDCODE_ERASE: /* Erase N characters from the cursor position */
|
2013-06-21 17:42:09 -06:00
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
int last;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Get the last position to clear and make sure that the last
|
|
|
|
* position is on the SLCD.
|
|
|
|
*/
|
|
|
|
|
|
|
|
last = g_slcdstate.curpos + count - 1;
|
|
|
|
if (last >= SLCD_NCHARS)
|
|
|
|
{
|
|
|
|
last = SLCD_NCHARS - 1;
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* Erase N characters after the current cursor position left
|
|
|
|
* by one
|
|
|
|
*/
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
for (i = g_slcdstate.curpos; i < last; i++)
|
|
|
|
{
|
2013-06-23 09:05:20 -06:00
|
|
|
slcd_writech(' ', i, 0);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
case SLCDCODE_CLEAR: /* Home the cursor and erase the entire display */
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2019-08-15 16:19:17 +00:00
|
|
|
/* This is like HOME followed by ERASEEOL.
|
|
|
|
* Home the cursor and fall through.
|
2013-06-21 17:42:09 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
g_slcdstate.curpos = 0;
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
case SLCDCODE_ERASEEOL: /* Erase from the cursor position to the end of line */
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* Erase characters after the current cursor position to the end of
|
|
|
|
* the line
|
|
|
|
*/
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
for (i = g_slcdstate.curpos; i < SLCD_NCHARS; i++)
|
|
|
|
{
|
2013-06-23 09:05:20 -06:00
|
|
|
slcd_writech(' ', i, 0);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Cursor movement */
|
|
|
|
|
|
|
|
case SLCDCODE_HOME: /* Cursor home */
|
|
|
|
{
|
|
|
|
g_slcdstate.curpos = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLCDCODE_END: /* Cursor end */
|
|
|
|
{
|
|
|
|
g_slcdstate.curpos = SLCD_NCHARS - 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLCDCODE_LEFT: /* Cursor left by N characters */
|
|
|
|
{
|
|
|
|
int tmp = (int)g_slcdstate.curpos - count;
|
|
|
|
|
|
|
|
/* Don't permit movement past the beginning of the SLCD */
|
|
|
|
|
|
|
|
if (tmp < 0)
|
|
|
|
{
|
|
|
|
tmp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the new cursor position */
|
|
|
|
|
|
|
|
g_slcdstate.curpos = (uint8_t)tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLCDCODE_RIGHT: /* Cursor right by N characters */
|
|
|
|
{
|
|
|
|
int tmp = (int)g_slcdstate.curpos + count;
|
|
|
|
|
|
|
|
/* Don't permit movement past the end of the SLCD */
|
|
|
|
|
|
|
|
if (tmp >= SLCD_NCHARS)
|
|
|
|
{
|
|
|
|
tmp = SLCD_NCHARS - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the new cursor position */
|
|
|
|
|
|
|
|
g_slcdstate.curpos = (uint8_t)tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLCDCODE_UP: /* Cursor up by N lines */
|
|
|
|
case SLCDCODE_DOWN: /* Cursor down by N lines */
|
|
|
|
case SLCDCODE_PAGEUP: /* Cursor up by N pages */
|
|
|
|
case SLCDCODE_PAGEDOWN: /* Cursor down by N pages */
|
|
|
|
break; /* Not supportable on this SLCD */
|
|
|
|
|
|
|
|
/* Blinking */
|
|
|
|
|
|
|
|
case SLCDCODE_BLINKSTART: /* Start blinking with current cursor position */
|
|
|
|
case SLCDCODE_BLINKEND: /* End blinking after the current cursor position */
|
|
|
|
case SLCDCODE_BLINKOFF: /* Turn blinking off */
|
|
|
|
break; /* Not implemented */
|
|
|
|
|
|
|
|
/* These are actually unreportable errors */
|
|
|
|
|
|
|
|
default:
|
|
|
|
case SLCDCODE_NORMAL: /* Not a special keycode */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
slcd_dumpstate("AFTER ACTION");
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static ssize_t slcd_read(struct file *filep,
|
|
|
|
char *buffer, size_t len)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Try to read the entire display. Notice that the seek offset
|
2013-09-28 16:50:07 -06:00
|
|
|
* (filep->f_pos) is ignored. It probably should be taken into account
|
2013-06-21 17:42:09 -06:00
|
|
|
* and also updated after each read and write.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < SLCD_NCHARS && ret < len; i++)
|
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Check if the character is decorated with a preceding period */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
if (ret < len && g_slcdstate.options[i] != 0)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
if ((g_slcdstate.options[i] & SLCD_DP) != 0)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
|
|
|
*buffer++ = '.';
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
}
|
2019-08-15 16:19:17 +00:00
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Return the character */
|
|
|
|
|
|
|
|
*buffer++ = g_slcdstate.buffer[i];
|
|
|
|
ret++;
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
slcd_dumpstate("READ");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static ssize_t slcd_write(struct file *filep,
|
|
|
|
const char *buffer, size_t len)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2022-12-04 19:50:09 +08:00
|
|
|
struct lib_meminstream_s instream;
|
2013-06-21 17:42:09 -06:00
|
|
|
struct slcdstate_s state;
|
|
|
|
enum slcdret_e result;
|
|
|
|
uint8_t ch;
|
|
|
|
uint8_t count;
|
2013-06-23 09:05:20 -06:00
|
|
|
uint8_t options;
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/* Initialize the stream for use with the SLCD CODEC */
|
|
|
|
|
2022-12-04 19:50:09 +08:00
|
|
|
lib_meminstream(&instream, buffer, len);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
/* Initialize the SLCD decode state buffer */
|
|
|
|
|
|
|
|
memset(&state, 0, sizeof(struct slcdstate_s));
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Decode and process every byte in the input buffer */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
options = 0;
|
2022-12-04 19:50:09 +08:00
|
|
|
while ((result = slcd_decode(&instream.public,
|
|
|
|
&state, &ch, &count)) != SLCDRET_EOF)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("slcd_decode returned result=%d char=%d count=%d\n",
|
2013-06-21 17:42:09 -06:00
|
|
|
result, ch, count);
|
|
|
|
|
|
|
|
if (result == SLCDRET_CHAR) /* A normal character was returned */
|
|
|
|
{
|
|
|
|
/* Check for ASCII control characters */
|
|
|
|
|
|
|
|
if (ch < ASCII_SPACE)
|
|
|
|
{
|
|
|
|
/* All are ignored except for backspace and carriage return */
|
|
|
|
|
|
|
|
if (ch == ASCII_BS)
|
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Perform the backward deletion */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
slcd_action(SLCDCODE_BACKDEL, 1);
|
|
|
|
}
|
|
|
|
else if (ch == ASCII_CR)
|
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Perform the carriage return */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
slcd_action(SLCDCODE_HOME, 0);
|
|
|
|
}
|
2013-06-22 10:39:25 -06:00
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* Ignore dots before control characters (all of them?) */
|
2013-06-22 10:39:25 -06:00
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
options = 0;
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Handle characters decoreated with a preceding period */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
else if (ch == '.')
|
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
/* The next character will need a dot in front of it */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
options |= SLCD_DP;
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle ASCII_DEL */
|
|
|
|
|
|
|
|
else if (ch == ASCII_DEL)
|
|
|
|
{
|
2020-02-23 02:31:14 +08:00
|
|
|
/* Perform the forward deletion */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
slcd_action(SLCDCODE_FWDDEL, 1);
|
2013-06-23 09:05:20 -06:00
|
|
|
options = 0;
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The rest of the 7-bit ASCII characters are fair game */
|
|
|
|
|
|
|
|
else if (ch < 128)
|
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("ch: %c[%02x] options: %02x\n", ch, ch, options);
|
2013-06-22 10:39:25 -06:00
|
|
|
|
|
|
|
/* Write the character at the current cursor position */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
slcd_writech(ch, g_slcdstate.curpos, options);
|
|
|
|
options = 0;
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* And advance the cursor position */
|
|
|
|
|
|
|
|
if (g_slcdstate.curpos < (SLCD_NCHARS - 1))
|
|
|
|
{
|
|
|
|
g_slcdstate.curpos++;
|
|
|
|
}
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
slcd_dumpstate("AFTER APPEND");
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* (result == SLCDRET_SPEC) */ /* A special SLCD action was returned */
|
|
|
|
{
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Then Perform the action */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
slcd_action((enum slcdcode_e)ch, count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
/* Ignore any dots with no following characters */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/* Assume that the entire input buffer was processed */
|
|
|
|
|
|
|
|
return (ssize_t)len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_poll
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static int slcd_ioctl(struct file *filep, int cmd, unsigned long arg)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
/* SLCDIOC_GETATTRIBUTES: Get the attributes of the SLCD
|
|
|
|
*
|
2019-08-15 16:19:17 +00:00
|
|
|
* argument: Pointer to struct slcd_attributes_s in which values will
|
|
|
|
* be returned
|
2013-06-21 17:42:09 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
case SLCDIOC_GETATTRIBUTES:
|
|
|
|
{
|
2022-04-17 14:01:48 +08:00
|
|
|
struct slcd_attributes_s *attr =
|
|
|
|
(struct slcd_attributes_s *)((uintptr_t)arg);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("SLCDIOC_GETATTRIBUTES:\n");
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
if (!attr)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr->nrows = SLCD_NROWS;
|
|
|
|
attr->ncolumns = SLCD_NCHARS;
|
2013-06-23 09:05:20 -06:00
|
|
|
attr->nbars = SLCD_NBARS;
|
2013-06-21 17:42:09 -06:00
|
|
|
attr->maxcontrast = SLCD_MAXCONTRAST;
|
|
|
|
attr->maxbrightness = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* SLCDIOC_CURPOS: Get the SLCD cursor positioni (rows x characters)
|
|
|
|
*
|
|
|
|
* argument: Pointer to struct slcd_curpos_s in which values will be
|
|
|
|
* returned
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SLCDIOC_CURPOS:
|
|
|
|
{
|
2022-04-17 14:01:48 +08:00
|
|
|
struct slcd_curpos_s *curpos =
|
|
|
|
(struct slcd_curpos_s *)((uintptr_t)arg);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("SLCDIOC_CURPOS: row=0 column=%d\n", g_slcdstate.curpos);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
if (!curpos)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curpos->row = 0;
|
|
|
|
curpos->column = g_slcdstate.curpos;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
/* SLCDIOC_SETBAR: Set bars on a bar display
|
|
|
|
*
|
|
|
|
* argument: 32-bit bitset, with each bit corresponding to one bar.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SLCDIOC_SETBAR:
|
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("SLCDIOC_SETBAR: arg=0x%02lx\n", arg);
|
2013-06-23 09:05:20 -06:00
|
|
|
|
|
|
|
if ((arg & 1) != 0)
|
|
|
|
{
|
|
|
|
slcd_setpixel(SLCD_RNG0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slcd_clrpixel(SLCD_RNG0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((arg & 2) != 0)
|
|
|
|
{
|
|
|
|
slcd_setpixel(SLCD_RNG1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slcd_clrpixel(SLCD_RNG1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((arg & 4) != 0)
|
|
|
|
{
|
|
|
|
slcd_setpixel(SLCD_RNG2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slcd_clrpixel(SLCD_RNG2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((arg & 8) != 0)
|
|
|
|
{
|
|
|
|
slcd_clrpixel(SLCD_RNG3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
slcd_setpixel(SLCD_RNG3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
/* SLCDIOC_GETCONTRAST: Get the current contrast setting
|
|
|
|
*
|
|
|
|
* argument: Pointer type int that will receive the current contrast
|
|
|
|
* setting
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SLCDIOC_GETCONTRAST:
|
|
|
|
{
|
2022-04-17 14:01:48 +08:00
|
|
|
int *contrast = (int *)((uintptr_t)arg);
|
2013-06-21 17:42:09 -06:00
|
|
|
if (!contrast)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*contrast = (int)slcd_getcontrast();
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("SLCDIOC_GETCONTRAST: contrast=%d\n", *contrast);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* SLCDIOC_SETCONTRAST: Set the contrast to a new value
|
|
|
|
*
|
|
|
|
* argument: The new contrast value
|
|
|
|
*/
|
|
|
|
|
|
|
|
case SLCDIOC_SETCONTRAST:
|
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("SLCDIOC_SETCONTRAST: arg=%ld\n", arg);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
if (arg > SLCD_MAXCONTRAST)
|
|
|
|
{
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
return slcd_setcontrast((unsigned int)arg);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLCDIOC_GETBRIGHTNESS: /* Get the current brightness setting */
|
|
|
|
case SLCDIOC_SETBRIGHTNESS: /* Set the brightness to a new value */
|
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: slcd_poll
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-04-17 14:01:48 +08:00
|
|
|
static int slcd_poll(struct file *filep, struct pollfd *fds,
|
|
|
|
bool setup)
|
2013-06-21 17:42:09 -06:00
|
|
|
{
|
|
|
|
if (setup)
|
|
|
|
{
|
2020-02-23 16:50:23 +08:00
|
|
|
/* Data is always available to be read / Data can always be written */
|
2013-06-21 17:42:09 -06:00
|
|
|
|
2022-09-19 11:08:57 +08:00
|
|
|
poll_notify(&fds, 1, POLLIN | POLLOUT);
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sam_slcd_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2021-03-18 09:57:48 +01:00
|
|
|
* Initialize the SAM4L Xplained Pro LCD hardware and register the
|
|
|
|
* character driver as /dev/slcd0.
|
2013-06-21 17:42:09 -06:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int sam_slcd_initialize(void)
|
|
|
|
{
|
|
|
|
uint32_t regval;
|
|
|
|
int ret = OK;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Only initialize the driver once. */
|
|
|
|
|
|
|
|
if (!g_slcdstate.initialized)
|
|
|
|
{
|
2016-06-11 11:59:51 -06:00
|
|
|
lcdinfo("Initializing\n");
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/* Configure LCD GPIO pins */
|
|
|
|
|
|
|
|
for (i = 0; i < SLCD_NPINS; i++)
|
|
|
|
{
|
|
|
|
sam_configgpio(g_slcdgpio[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable APB clock for LCDCA */
|
|
|
|
|
|
|
|
sam_lcdca_enableclk();
|
|
|
|
|
2019-08-15 16:19:17 +00:00
|
|
|
/* Here we require that either CONFIG_SAM34_OSC32K or
|
|
|
|
* CONFIG_SAM34_RC32K is defined in the configuration.
|
|
|
|
* In that case, the source clock was initialized during boot up
|
|
|
|
* and we can be assured that it is read for use now.
|
2013-06-21 17:42:09 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Disable the LCD controller and frame counters */
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_DIS | LCDCA_CR_FC0DIS | LCDCA_CR_FC1DIS |
|
|
|
|
LCDCA_CR_FC2DIS, SAM_LCDCA_CR);
|
|
|
|
|
|
|
|
/* Configure LCD controller timing */
|
|
|
|
|
|
|
|
regval = BOARD_TIM_PRES | LCDCA_TIM_CLKDIV(BOARD_TIM_CLOCKDIV) |
|
|
|
|
LCDCA_TIM_FC0(BOARD_TIM_FC0) | LCDCA_TIM_FC1(BOARD_TIM_FC1) |
|
|
|
|
LCDCA_TIM_FC2(BOARD_TIM_FC2);
|
|
|
|
putreg32(regval, SAM_LCDCA_TIM);
|
|
|
|
|
|
|
|
/* Setup the LCD controller configuration.
|
|
|
|
*
|
|
|
|
* External bias generation (XBIAS): Controlled by board setting
|
|
|
|
* Waveform mode: Controlled by board setting
|
|
|
|
* Blank LCD: No
|
|
|
|
* Lock: No
|
|
|
|
* Duty: Controlled by board setting
|
|
|
|
* Fine Contrast (FCST): 0
|
|
|
|
* Number of segments (NSU): Controlled by board setting
|
|
|
|
*/
|
|
|
|
|
2014-04-13 16:22:22 -06:00
|
|
|
regval =
|
2013-06-21 17:42:09 -06:00
|
|
|
#ifdef BOARD_XBIAS
|
|
|
|
LCDCA_CFG_XBIAS |
|
|
|
|
#endif
|
|
|
|
#ifndef BOARD_LPWAVE
|
|
|
|
LCDCA_CFG_WMOD |
|
|
|
|
#endif
|
|
|
|
LCD_DUTY |
|
|
|
|
LCDCA_CFG_FCST(0) |
|
2013-06-22 10:39:25 -06:00
|
|
|
LCDCA_CFG_NSU(BOARD_SLCD_NSEG);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
putreg32(regval, SAM_LCDCA_CFG);
|
|
|
|
|
|
|
|
/* Provide an initial contrast setting */
|
|
|
|
|
|
|
|
slcd_setcontrast(BOARD_INITIAL_CONTRAST);
|
|
|
|
|
|
|
|
/* Turn off blanking of display segments */
|
|
|
|
|
|
|
|
regval = getreg32(SAM_LCDCA_CFG);
|
|
|
|
regval &= ~LCDCA_CFG_BLANK;
|
|
|
|
putreg32(regval, SAM_LCDCA_CFG);
|
|
|
|
|
|
|
|
/* Enable the display controller */
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_EN, SAM_LCDCA_CR);
|
|
|
|
|
|
|
|
/* Clear all display memory */
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_CDM, SAM_LCDCA_CR);
|
|
|
|
|
|
|
|
/* Wait for the LCD to be fully enabled */
|
|
|
|
|
|
|
|
while ((getreg32(SAM_LCDCA_SR) & LCDCA_SR_EN) == 0);
|
|
|
|
|
|
|
|
/* Enable frame counters */
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_FC0EN, SAM_LCDCA_CR);
|
|
|
|
while ((getreg32(SAM_LCDCA_SR) & LCDCA_SR_FC0S) == 0);
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_FC1EN, SAM_LCDCA_CR);
|
|
|
|
while ((getreg32(SAM_LCDCA_SR) & LCDCA_SR_FC1S) == 0);
|
|
|
|
|
|
|
|
putreg32(LCDCA_CR_FC2EN, SAM_LCDCA_CR);
|
|
|
|
while ((getreg32(SAM_LCDCA_SR) & LCDCA_SR_FC2S) == 0);
|
|
|
|
|
|
|
|
/* Make sure that blinking and circular shifting is off */
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
putreg32(LCDCA_CR_BSTOP | LCDCA_CR_CSTOP, SAM_LCDCA_CR);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/* Disable any automated display */
|
|
|
|
|
|
|
|
regval = getreg32(SAM_LCDCA_ACMCFG);
|
|
|
|
regval &= ~LCDCA_ACMCFG_EN;
|
|
|
|
putreg32(regval, SAM_LCDCA_ACMCFG);
|
|
|
|
|
|
|
|
/* Initialize display memory */
|
|
|
|
|
2013-06-23 09:05:20 -06:00
|
|
|
putreg32(0, SAM_LCDCA_DRL0);
|
|
|
|
putreg32(0, SAM_LCDCA_DRH0);
|
|
|
|
putreg32(0, SAM_LCDCA_DRL1);
|
|
|
|
putreg32(0, SAM_LCDCA_DRH1);
|
|
|
|
putreg32(0, SAM_LCDCA_DRL2);
|
|
|
|
putreg32(0, SAM_LCDCA_DRH2);
|
|
|
|
putreg32(0, SAM_LCDCA_DRL3);
|
|
|
|
putreg32(0, SAM_LCDCA_DRH3);
|
|
|
|
|
|
|
|
/* Turn on the Atmel pixel */
|
|
|
|
|
|
|
|
slcd_setpixel(SLCD_ATMEL);
|
2013-06-21 17:42:09 -06:00
|
|
|
|
|
|
|
/* Register the LCD device driver */
|
|
|
|
|
2018-11-25 14:00:20 -06:00
|
|
|
ret = register_driver("/dev/slcd0", &g_slcdops, 0644, &g_slcdstate);
|
2013-06-21 17:42:09 -06:00
|
|
|
g_slcdstate.initialized = true;
|
|
|
|
|
|
|
|
/* Turn on the backlight */
|
|
|
|
|
|
|
|
sam_gpiowrite(GPIO_LCD1_BL, true);
|
2013-06-22 17:01:44 -06:00
|
|
|
|
2013-06-21 17:42:09 -06:00
|
|
|
slcd_dumpstate("AFTER INITIALIZATION");
|
2013-06-22 17:01:44 -06:00
|
|
|
slcd_dumpslcd("AFTER INITIALIZATION");
|
2013-06-21 17:42:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-22 10:39:25 -06:00
|
|
|
#endif /* CONFIG_SAM34_LCDCA && CONFIG_SAM4L_XPLAINED_SLCD1MODULE */
|