* drivers/lcd/ssd1306_i2c.c
*
* SPDX-License-Identifier: Apache-2.0
*
* 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 <string.h>
#include <nuttx/kmalloc.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/lcd/ssd1306.h>
#include "ssd1306.h"
#if defined(CONFIG_LCD_SSD1306) && defined(CONFIG_LCD_SSD1306_I2C)
* Public Functions
****************************************************************************/
* Name: ssd1306_sendbyte
*
* Description:
* Write an 8-bit value into SSD1306
*
****************************************************************************/
int ssd1306_sendbyte(FAR struct ssd1306_dev_s *priv, uint8_t regval)
{
*
* Start - I2C_Write_Address - SSD1306_Reg_Address - SSD1306_Write_Data
* - STOP
*/
struct i2c_msg_s msg;
uint8_t txbuffer[2];
int ret;
#ifdef CONFIG_LCD_SSD1306_REGDEBUG
_err("-> 0x%02x\n", regval);
#endif
* address followed by one byte of data.
*/
txbuffer[0] = 0x00;
txbuffer[1] = regval;
msg.frequency = CONFIG_SSD1306_I2CFREQ;
msg.addr = priv->addr;
msg.flags = 0;
msg.buffer = txbuffer;
msg.length = 2;
* then STOP */
ret = I2C_TRANSFER(priv->i2c, &msg, 1);
if (ret < 0)
{
lcderr("ERROR: I2C_TRANSFER failed: %d\n", ret);
}
return ret;
}
* 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)
{
struct i2c_msg_s msg[2];
uint8_t transfer_mode;
int ret;
*
* Start - I2C_Write_Address - Data transfer select - SSD1306_Write_Data
* - STOP
*/
transfer_mode = 0x40;
msg[0].frequency = CONFIG_SSD1306_I2CFREQ;
msg[0].addr = priv->addr;
msg[0].flags = I2C_M_NOSTOP;
msg[0].buffer = &transfer_mode;
msg[0].length = 1;
msg[1].frequency = CONFIG_SSD1306_I2CFREQ;
msg[1].addr = priv->addr;
msg[1].flags = I2C_M_NOSTART;
msg[1].buffer = data;
msg[1].length = len;
ret = I2C_TRANSFER(priv->i2c, msg, 2);
if (ret < 0)
{
lcderr("ERROR: I2C_TRANSFER failed: %d\n", ret);
}
return ret;
}
#endif