123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- /****************************************************************************
- * drivers/lcd/ssd1306_spi.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.
- *
- ****************************************************************************/
- /****************************************************************************
- * Included Files
- ****************************************************************************/
- #include <nuttx/config.h>
- #include <unistd.h>
- #include <errno.h>
- #include <debug.h>
- #include <nuttx/kmalloc.h>
- #include <nuttx/lcd/ssd1306.h>
- #include <nuttx/spi/spi.h>
- #include "ssd1306.h"
- #if defined(CONFIG_LCD_SSD1306) && defined(CONFIG_LCD_SSD1306_SPI)
- /****************************************************************************
- * Public Functions
- ****************************************************************************/
- /****************************************************************************
- * Name: ssd1306_configspi
- *
- * Description:
- *
- ****************************************************************************/
- void ssd1306_configspi(FAR struct spi_dev_s *spi)
- {
- lcdinfo("Mode: %d Bits: 8 Frequency: %d\n",
- CONFIG_SSD1306_SPIMODE, CONFIG_SSD1306_FREQUENCY);
- /* Configure SPI for the SSD1306 */
- SPI_SETMODE(spi, CONFIG_SSD1306_SPIMODE);
- SPI_SETBITS(spi, 8);
- SPI_HWFEATURES(spi, 0);
- SPI_SETFREQUENCY(spi, CONFIG_SSD1306_FREQUENCY);
- }
- /****************************************************************************
- * Name: ssd1306_sendbyte
- *
- * Description:
- * Write a value to an 8-bit value to SSD1306
- *
- ****************************************************************************/
- int ssd1306_sendbyte(FAR struct ssd1306_dev_s *priv, uint8_t regval)
- {
- #ifdef CONFIG_LCD_SSD1306_REGDEBUG
- _err("->0x%02x\n", regval);
- #endif
- /* Send byte value to display */
- SPI_SEND(priv->spi, regval);
- return OK;
- }
- /****************************************************************************
- * Name: ssd1306_sendblk
- *
- * Description:
- * Write an array of bytes to SSD1306
- *
- ****************************************************************************/
- int ssd1306_sendblk(FAR struct ssd1306_dev_s *priv,
- uint8_t *data, uint8_t len)
- {
- /* Send byte value to display */
- SPI_SNDBLOCK(priv->spi, data, len);
- return OK;
- }
- /****************************************************************************
- * Name: ssd1306_select
- *
- * Description:
- * Enable/Disable SSD1306 SPI CS
- *
- ****************************************************************************/
- void ssd1306_select(FAR struct ssd1306_dev_s *priv, bool cs)
- {
- /* If we are selecting the device */
- if (cs == true)
- {
- /* If SPI bus is shared then lock and configure it */
- SPI_LOCK(priv->spi, true);
- ssd1306_configspi(priv->spi);
- }
- /* Select/deselect SPI device */
- SPI_SELECT(priv->spi, SPIDEV_DISPLAY(0), cs);
- /* If we are deselecting the device */
- if (cs == false)
- {
- /* Unlock bus */
- SPI_LOCK(priv->spi, false);
- }
- }
- /****************************************************************************
- * Name: ssd1306_cmddata
- *
- * Description:
- * Select Command/Data mode for SSD1306
- *
- ****************************************************************************/
- void ssd1306_cmddata(FAR struct ssd1306_dev_s *priv, bool cmd)
- {
- /* Select command transfer */
- SPI_CMDDATA(priv->spi, SPIDEV_DISPLAY(0), cmd);
- }
- #endif /* CONFIG_LCD_SSD1306 && CONFIG_LCD_SSD1306_SPI */
|