- folder structure reordered
- unnecessary drivers removed
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* battery_monitor.c
|
||||
*
|
||||
* Created on: Dec 23, 2012
|
||||
* Author: tkl
|
||||
*/
|
||||
#include "stddef.h"
|
||||
#include "adc.h"
|
||||
#include "battery_monitor.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
struct battery_monitor_voltage get_voltage(const struct battery_monitor *device)
|
||||
{
|
||||
struct battery_monitor_voltage ret;
|
||||
ret.valid = false;
|
||||
if(NULL == device) {
|
||||
return ret;
|
||||
}
|
||||
adc_open(device->adc);
|
||||
ret.raw = adc_read(device->adc, device->timeout);
|
||||
adc_close(device->adc);
|
||||
ret.voltage = ret.raw * device->factor / device->divider + device->offset;
|
||||
ret.valid = true;
|
||||
return ret;
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* battery_monitor.h
|
||||
*
|
||||
* Created on: Dec 23, 2012
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#ifndef BATTERY_MONITOR_H_
|
||||
#define BATTERY_MONITOR_H_
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief battery monitor device.
|
||||
struct battery_monitor {
|
||||
const struct adc *adc; //!< Adc device for the battery monitor.
|
||||
const unsigned short timeout; //!< Adc measurement timeout.
|
||||
const int factor; //!< Factor to calculate voltage from adc result.
|
||||
const int divider; //!< Divider to calculate voltage from adc result.
|
||||
const int offset; //!< Offset to calculate voltage from adc result.
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//! \brief Value container for the battery monitor.
|
||||
struct battery_monitor_voltage {
|
||||
unsigned short voltage; //!< Calculated voltage.
|
||||
unsigned short raw; //!< Raw value of the adc.
|
||||
bool valid; //!< Indicates if result is valid.
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
struct battery_monitor_voltage get_voltage(const struct battery_monitor * device);
|
||||
|
||||
#endif /* BATTERY_MONITOR_H_ */
|
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* cc110x.c
|
||||
*
|
||||
* Created on: Jul 20, 2012
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "board.h"
|
||||
#include "stack.h"
|
||||
#include "queue.h"
|
||||
#include "thread.h"
|
||||
#include "schedule.h"
|
||||
#include "irq.h"
|
||||
#include "sys_tick.h"
|
||||
#include "cc110x.h"
|
||||
|
||||
static volatile bool tx_condition;
|
||||
extern volatile struct thread_context *current_thread;
|
||||
|
||||
static void it_cb(const struct cc110x *cc110x, enum cc110x_it_type it_type);
|
||||
|
||||
int cc110x_open(const struct cc110x *cc110x)
|
||||
{
|
||||
if(NULL == cc110x)
|
||||
return (-1);
|
||||
|
||||
tx_condition = false;
|
||||
cc110x->fp->init(cc110x);
|
||||
cc110x->fp->set_it_callback(cc110x->arch_dep_device, it_cb, cc110x);
|
||||
cc110x_set_radio_mode(cc110x, CC110X_RADIO_MODE_PWD);
|
||||
cc110x_write_pa_table(cc110x);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int cc110x_close(const struct cc110x *cc110x)
|
||||
{
|
||||
cc110x_set_radio_mode(cc110x, CC110X_RADIO_MODE_PWD);
|
||||
blocking_read_wakeup(cc110x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cc110x_set_radio_mode(const struct cc110x *cc110x,
|
||||
enum cc110x_radio_mode mode)
|
||||
{
|
||||
if(NULL == cc110x) {
|
||||
return;
|
||||
}
|
||||
*(cc110x->radio_mode) = mode;
|
||||
enum cc110x_strobe_cmd cmd = STROBE_SIDLE;
|
||||
switch(mode) {
|
||||
case CC110X_RADIO_MODE_NONE: return;
|
||||
case CC110X_RADIO_MODE_IDLE: cmd = STROBE_SIDLE; break;
|
||||
case CC110X_RADIO_MODE_RX: cmd = STROBE_SRX; break;
|
||||
case CC110X_RADIO_MODE_TX: cmd = STROBE_STX; break;
|
||||
case CC110X_RADIO_MODE_PWD: cmd = STROBE_SPWD; break;
|
||||
}
|
||||
cc110x->fp->strobe(cc110x->arch_dep_device, cmd);
|
||||
}
|
||||
|
||||
enum cc110x_radio_mode cc110x_get_radio_mode(const struct cc110x *cc110x)
|
||||
{
|
||||
if(NULL == cc110x)
|
||||
return (CC110X_RADIO_MODE_NONE);
|
||||
return (*(cc110x->radio_mode));
|
||||
}
|
||||
|
||||
void cc110x_write_pa_table(const struct cc110x *cc110x)
|
||||
{
|
||||
if(NULL == cc110x)
|
||||
return;
|
||||
cc110x->fp->write_pa_table(cc110x->arch_dep_device);
|
||||
}
|
||||
|
||||
void cc110x_strobe(const struct cc110x *cc110x, enum cc110x_strobe_cmd cmd)
|
||||
{
|
||||
if(NULL == cc110x)
|
||||
return;
|
||||
cc110x->fp->strobe(cc110x->arch_dep_device, cmd);
|
||||
}
|
||||
|
||||
int cc110x_write(const struct cc110x *cc110x, const char *buffer,
|
||||
int size)
|
||||
{
|
||||
enum cc110x_radio_mode mode;
|
||||
int ret;
|
||||
if((NULL == cc110x) || (NULL == buffer))
|
||||
return (-1);
|
||||
mode = cc110x_get_radio_mode(cc110x);
|
||||
cc110x_set_radio_mode(cc110x, CC110X_RADIO_MODE_IDLE);
|
||||
cc110x_strobe(cc110x, STROBE_SFTX);
|
||||
ret = cc110x->fp->write(cc110x->arch_dep_device, buffer, size);
|
||||
tx_condition = true;
|
||||
cc110x_set_radio_mode(cc110x, CC110X_RADIO_MODE_TX);
|
||||
while(tx_condition);
|
||||
cc110x_set_radio_mode(cc110x, CC110X_RADIO_MODE_IDLE);
|
||||
cc110x_strobe(cc110x, STROBE_SFTX);
|
||||
cc110x_set_radio_mode(cc110x, mode);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int cc110x_read(const struct cc110x *cc110x, char *buffer, int size)
|
||||
{
|
||||
int ret;
|
||||
if((NULL == cc110x) || (NULL == buffer))
|
||||
return (-1);
|
||||
if(0 == cc110x_get_rx_count(cc110x)) {
|
||||
unsigned int irq = disable_irq();
|
||||
current_thread->status = THREAD_STATUS_BLOCKING;
|
||||
current_thread->wakeup_blocking_source = (void*) cc110x;
|
||||
restore_irq(irq);
|
||||
schedule();
|
||||
}
|
||||
enum cc110x_radio_mode mode = cc110x_get_radio_mode(cc110x);
|
||||
cc110x_set_radio_mode(cc110x, CC110X_RADIO_MODE_IDLE);
|
||||
ret = cc110x_get_rx_count(cc110x);
|
||||
ret = cc110x->fp->read(cc110x->arch_dep_device, buffer, ret);
|
||||
cc110x_strobe(cc110x, STROBE_SFRX);
|
||||
cc110x_set_radio_mode(cc110x, mode);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int cc110x_get_rx_count(const struct cc110x *cc110x)
|
||||
{
|
||||
if(NULL == cc110x)
|
||||
return (-1);
|
||||
return (cc110x->fp->get_rx_count(cc110x->arch_dep_device));
|
||||
}
|
||||
|
||||
static void it_cb(const struct cc110x *cc110x,
|
||||
enum cc110x_it_type it_type)
|
||||
{
|
||||
if(NULL == cc110x)
|
||||
return;
|
||||
switch(it_type) {
|
||||
case IT_TYPE_NONE:
|
||||
break;
|
||||
case IT_TYPE_RX_COMPLETE:
|
||||
blocking_read_wakeup(cc110x);
|
||||
break;
|
||||
case IT_TYPE_TX_COMPLETE:
|
||||
tx_condition = false;
|
||||
break;
|
||||
}
|
||||
}
|
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* cc110x.h
|
||||
*
|
||||
* Created on: Jul 20, 2012
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#ifndef CC110X_H_
|
||||
#define CC110X_H_
|
||||
|
||||
enum cc110x_radio_mode {
|
||||
CC110X_RADIO_MODE_NONE = 0,
|
||||
CC110X_RADIO_MODE_IDLE,
|
||||
CC110X_RADIO_MODE_RX,
|
||||
CC110X_RADIO_MODE_TX,
|
||||
CC110X_RADIO_MODE_PWD
|
||||
};
|
||||
|
||||
enum cc110x_strobe_cmd {
|
||||
STROBE_SRES = 0,
|
||||
STROBE_SFSTXON,
|
||||
STROBE_SXOFF,
|
||||
STROBE_SCAL,
|
||||
STROBE_SRX,
|
||||
STROBE_STX,
|
||||
STROBE_SIDLE,
|
||||
STROBE_SWOR,
|
||||
STROBE_SPWD,
|
||||
STROBE_SFRX,
|
||||
STROBE_SFTX,
|
||||
STROBE_SWORRST,
|
||||
STROBE_SNOP
|
||||
};
|
||||
|
||||
enum cc110x_it_type {
|
||||
IT_TYPE_NONE = 0,
|
||||
IT_TYPE_RX_COMPLETE,
|
||||
IT_TYPE_TX_COMPLETE
|
||||
};
|
||||
|
||||
typedef void (*cc110x_fp_init)(const void *);
|
||||
typedef void (*cc110x_fp_write_pa_table)(const void *);
|
||||
typedef void (*cc110x_fp_set_radio_mode)(const void *, enum cc110x_radio_mode);
|
||||
typedef char (*cc110x_fp_strobe)(const void *, enum cc110x_strobe_cmd);
|
||||
typedef int (*cc110x_fp_write)(const void *, const char *, int);
|
||||
typedef int (*cc110x_fp_read)(const void *, char *, int);
|
||||
typedef int (*cc110x_fp_set_it_cb)(const void *, const void *, const void *);
|
||||
typedef int (*cc110x_fp_get_rx_count)(const void *);
|
||||
|
||||
//! \brief Contains the function pointer to access the cc110x driver.
|
||||
struct cc110x_fp {
|
||||
/*! Function pointer to the init function. */
|
||||
const cc110x_fp_init init;
|
||||
/*! Function pointer to the strobe function. */
|
||||
const cc110x_fp_strobe strobe;
|
||||
/*! Function pointer to the write function. */
|
||||
const cc110x_fp_write write;
|
||||
/*! Function pointer to the read function. */
|
||||
const cc110x_fp_read read;
|
||||
/*! Function pointer to the write_pa_table function. */
|
||||
const cc110x_fp_write_pa_table write_pa_table;
|
||||
/*! Function pointer to the set_it_callback function. */
|
||||
const cc110x_fp_set_it_cb set_it_callback;
|
||||
/*! Function pointer to the get_rx_count function. */
|
||||
const cc110x_fp_get_rx_count get_rx_count;
|
||||
};
|
||||
|
||||
//! \brief The cc110x driver object.
|
||||
struct cc110x {
|
||||
/*! Radio mode. */
|
||||
enum cc110x_radio_mode *radio_mode;
|
||||
/*! Architecture depended underlaying device (i.e. spi_t or NULL). */
|
||||
const void *arch_dep_device;
|
||||
/*! Function pointer for the cc110x driver access. */
|
||||
const struct cc110x_fp *fp;
|
||||
};
|
||||
|
||||
int cc110x_open(const struct cc110x *cc110x);
|
||||
int cc110x_close(const struct cc110x *cc110x);
|
||||
int cc110x_write(const struct cc110x *cc110x, const char *buffer, int size);
|
||||
int cc110x_read(const struct cc110x *cc110x, char *buffer, int size);
|
||||
int cc110x_get_rx_count(const struct cc110x *cc110x);
|
||||
void cc110x_set_radio_mode(const struct cc110x *cc110x, enum cc110x_radio_mode mode);
|
||||
enum cc110x_radio_mode cc110x_get_radio_mode(const struct cc110x *cc110x);
|
||||
void cc110x_write_pa_table(const struct cc110x *cc110x);
|
||||
void cc110x_strobe(const struct cc110x *cc110x, enum cc110x_strobe_cmd cmd);
|
||||
|
||||
#endif /* CC110X_H_ */
|
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* ds75.c
|
||||
*
|
||||
* Created on: Aug 1, 2012
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include "ds75.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
#define TEMPERATURE_REGISTER_ADDR 0x00
|
||||
#define CONFIGURATION_REGISTER_ADDR 0x01
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ds75_open(const struct ds75 *device) {
|
||||
if(NULL == device) {
|
||||
return -1;
|
||||
}
|
||||
*device->config_value = 0x00;
|
||||
return device->i2c->fp->open(device->i2c->arch_dep_device);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ds75_close(const struct ds75 *device) {
|
||||
if(NULL == device) {
|
||||
return -1;
|
||||
}
|
||||
return device->i2c->fp->close(device->i2c->arch_dep_device);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ds75_set_precision(const struct ds75 *device, enum ds75_precision precision)
|
||||
{
|
||||
if(NULL == device) {
|
||||
return -1;
|
||||
}
|
||||
char cfg = *device->config_value | (precision << 5);
|
||||
char buffer[] = {CONFIGURATION_REGISTER_ADDR, cfg};
|
||||
int ret = device->i2c->fp->write(device->i2c->arch_dep_device,
|
||||
device->i2c_slave_addr, buffer, sizeof(buffer));
|
||||
if (ret >= 0) {
|
||||
*device->config_value = cfg;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
enum ds75_precision ds_75_get_precision(const struct ds75 *device) {
|
||||
if(NULL == device) {
|
||||
return DS_75_PRECISION_INVALID;
|
||||
}
|
||||
|
||||
char cfg = *device->config_value;
|
||||
cfg >>= 5;
|
||||
cfg &= 3;
|
||||
return (enum ds75_precision) cfg;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ds_75_shut_down(const struct ds75 *device) {
|
||||
if(NULL == device) {
|
||||
return -1;
|
||||
}
|
||||
char cfg = *device->config_value | (1 << 0);
|
||||
char buffer[] = {CONFIGURATION_REGISTER_ADDR, cfg};
|
||||
int ret = device->i2c->fp->write(device->i2c->arch_dep_device,
|
||||
device->i2c_slave_addr, buffer, sizeof(buffer));
|
||||
if (ret >= 0) {
|
||||
*device->config_value = cfg;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ds_75_wakeup(const struct ds75 *device) {
|
||||
if(NULL == device) {
|
||||
return -1;
|
||||
}
|
||||
char cfg = *device->config_value & ~(1 << 0);
|
||||
char buffer[] = {CONFIGURATION_REGISTER_ADDR, cfg};
|
||||
int ret = device->i2c->fp->write(device->i2c->arch_dep_device,
|
||||
device->i2c_slave_addr, buffer, sizeof(buffer));
|
||||
if (ret >= 0) {
|
||||
*device->config_value = cfg;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ds75_temperature ds_75_get_temperature(const struct ds75 *device) {
|
||||
struct ds75_temperature ret;
|
||||
ret.temperature = 0xFFFF;
|
||||
ret.raw[0] = 0xFF;
|
||||
ret.raw[1] = 0xFF;
|
||||
ret.valid = false;
|
||||
if(NULL == device) {
|
||||
return ret;
|
||||
}
|
||||
// set temperature register
|
||||
char addr = TEMPERATURE_REGISTER_ADDR;
|
||||
int res = device->i2c->fp->write(device->i2c->arch_dep_device, device->i2c_slave_addr, &addr, 1);
|
||||
if(res < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// read temperature register
|
||||
res = device->i2c->fp->read(device->i2c->arch_dep_device, device->i2c_slave_addr, ret.raw, 2);
|
||||
if(res < 0) {
|
||||
return ret;
|
||||
}
|
||||
ret.valid = true;
|
||||
|
||||
ret.temperature = ret.raw[0];
|
||||
if(ret.temperature & 0x0080) {
|
||||
ret.temperature |= 0xFF00;
|
||||
}
|
||||
ret.temperature *= 10;
|
||||
unsigned short s_low = (unsigned char)ret.raw[1];
|
||||
s_low >>= 4;
|
||||
s_low *= 625;
|
||||
s_low += 500;
|
||||
s_low /= 1000;
|
||||
ret.temperature += s_low;
|
||||
return ret;
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* ds75.h
|
||||
*
|
||||
* Created on: Aug 1, 2012
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#ifndef DS75_H_
|
||||
#define DS75_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "i2c.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
enum ds75_precision {
|
||||
DS_75_PRECISION_9_BIT = 0,
|
||||
DS_75_PRECISION_10_BIT,
|
||||
DS_75_PRECISION_11_BIT,
|
||||
DS_75_PRECISION_12_BIT,
|
||||
|
||||
DS_75_PRECISION_INVALID
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//! \brief The ds75 driver object.
|
||||
struct ds75 {
|
||||
const struct i2c * i2c; //!< The i2c device the ds75 is connected to.
|
||||
const char i2c_slave_addr; //!< The i2c slave address of the ds 75.
|
||||
char *const config_value; //!< Config value.
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//! \brief Data container for the ds 75 measurement result.
|
||||
struct ds75_temperature {
|
||||
short temperature; //!< Calculated temperature.
|
||||
char raw[2]; //!< Raw i2c result.
|
||||
bool valid; //!< Validity indicator.
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int ds75_open(const struct ds75 *device);
|
||||
int ds75_close(const struct ds75 *device);
|
||||
int ds75_set_precision(const struct ds75 *device, enum ds75_precision precision);
|
||||
enum ds75_precision ds_75_get_precision(const struct ds75 *device);
|
||||
int ds_75_shut_down(const struct ds75 *device);
|
||||
int ds_75_wakeup(const struct ds75 *device);
|
||||
struct ds75_temperature ds_75_get_temperature(const struct ds75 *device);
|
||||
|
||||
#endif /* DS75_H_ */
|
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* ssd1306.c
|
||||
*
|
||||
* Created on: Jan 13, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include "i2c.h"
|
||||
#include "font.h"
|
||||
#include "bitmap.h"
|
||||
#include "ssd1306.h"
|
||||
|
||||
#define MAX_COLUMN 128
|
||||
#define MAX_ROW 64
|
||||
#define PAGE_COUNT 8
|
||||
#define HEAD_PAGE_COUNT 2
|
||||
#define BODY_PAGE_COUNT PAGE_COUNT - HEAD_PAGE_COUNT
|
||||
|
||||
#define CMD_MODE 0x80
|
||||
#define DATA_MODE 0x40
|
||||
|
||||
#define COLUMN_ADDR 0x21
|
||||
#define PAGE_ADDR 0x22
|
||||
#define DISPLAY_OFF 0xAE
|
||||
|
||||
static const char init_sequence[] = {
|
||||
0x80, 0xAE, 0x80, 0x20, 0x80, 0x10, 0x80, 0xb0, 0x80, 0xc8, 0x80, 0x00,
|
||||
0x80, 0x10, 0x80, 0x40, 0x80, 0x81, 0x80, 0x7f, 0x80, 0xa1, 0x80, 0xa6,
|
||||
0x80, 0xa8, 0x80, 0x3f, 0x80, 0xa4, 0x80, 0xd3, 0x80, 0x00, 0x80, 0xd5,
|
||||
0x80, 0xf0, 0x80, 0xd9, 0x80, 0x22, 0x80, 0xda, 0x80, 0x12, 0x80, 0xdb,
|
||||
0x80, 0x20, 0x80, 0x8d, 0x80, 0x14, 0x80, 0xaf
|
||||
};
|
||||
|
||||
static int set_column(const struct ssd1306 *dev, char column)
|
||||
{
|
||||
char buf[6];
|
||||
buf[0] = CMD_MODE;
|
||||
buf[1] = COLUMN_ADDR;
|
||||
buf[2] = CMD_MODE;
|
||||
buf[3] = column;
|
||||
buf[4] = CMD_MODE;
|
||||
buf[5] = MAX_COLUMN - 1;
|
||||
return i2c_write(dev->dev, dev->i2c_addr, buf, 6);
|
||||
}
|
||||
|
||||
static int set_page(const struct ssd1306 *dev, char page)
|
||||
{
|
||||
char buf[6];
|
||||
buf[0] = CMD_MODE;
|
||||
buf[1] = PAGE_ADDR;
|
||||
buf[2] = CMD_MODE;
|
||||
buf[3] = page;
|
||||
buf[4] = CMD_MODE;
|
||||
buf[5] = MAX_ROW / PAGE_COUNT - 1;
|
||||
return i2c_write(dev->dev, dev->i2c_addr, buf, 6);
|
||||
}
|
||||
|
||||
static int clear_head(const struct ssd1306 *dev)
|
||||
{
|
||||
int ret, i, j;
|
||||
char buf[2];
|
||||
|
||||
ret = set_column(dev, 0);
|
||||
ret |= set_page(dev, 0);
|
||||
|
||||
buf[0] = DATA_MODE;
|
||||
buf[1] = 0x00;
|
||||
for(i = 0; i < HEAD_PAGE_COUNT; i++)
|
||||
for(j = 0; j < MAX_COLUMN; j++)
|
||||
ret |= i2c_write(dev->dev, dev->i2c_addr, buf, 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int clear_body(const struct ssd1306 *dev)
|
||||
{
|
||||
int ret, i, j;
|
||||
char buf[2];
|
||||
|
||||
ret = set_column(dev, 0);
|
||||
ret |= set_page(dev, 2);
|
||||
|
||||
buf[0] = DATA_MODE;
|
||||
buf[1] = 0x00;
|
||||
for(i = 0; i < BODY_PAGE_COUNT; i++)
|
||||
for(j = 0; j < MAX_COLUMN; j++)
|
||||
ret |= i2c_write(dev->dev, dev->i2c_addr, buf, 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int clear(const struct ssd1306 *dev)
|
||||
{
|
||||
int ret;
|
||||
ret = clear_head(dev);
|
||||
ret |= clear_body(dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ssd1306_open(const struct ssd1306 *dev)
|
||||
{
|
||||
int ret;
|
||||
ret = i2c_open((struct i2c *)dev->dev);
|
||||
ret |= i2c_write(dev->dev, dev->i2c_addr, init_sequence,
|
||||
sizeof(init_sequence) / sizeof(init_sequence[0]));
|
||||
ret |= clear(dev);
|
||||
ret |= set_column(dev, 0);
|
||||
ret |= set_page(dev, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ssd1306_close(const struct ssd1306 *dev)
|
||||
{
|
||||
int ret;
|
||||
char buf[2];
|
||||
buf[0] = CMD_MODE;
|
||||
buf[1] = DISPLAY_OFF;
|
||||
ret = i2c_write(dev->dev, dev->i2c_addr, buf, 2);
|
||||
ret |= i2c_close((struct i2c *)dev->dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ssd1306_write(const struct ssd1306 *dev, const struct bitmap *bitmap)
|
||||
{
|
||||
int ret, i, len = bitmap->x_size * bitmap->y_size / 8;
|
||||
char buf[2] = {DATA_MODE, 0x00};
|
||||
|
||||
if(len != MAX_COLUMN * PAGE_COUNT)
|
||||
return -1;
|
||||
ret = set_column(dev, 0);
|
||||
ret |= set_page(dev, 0);
|
||||
for(i = 0; i < len; i++) {
|
||||
buf[1] = bitmap->buffer[i];
|
||||
ret |= i2c_write(dev->dev, dev->i2c_addr, buf, 2);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* ssd1306.h
|
||||
*
|
||||
* Created on: Jan 13, 2016
|
||||
* Author: tkl
|
||||
*/
|
||||
|
||||
#ifndef SSD1306_H_
|
||||
#define SSD1306_H_
|
||||
|
||||
struct ssd1306 {
|
||||
const struct i2c *dev;
|
||||
const char i2c_addr;
|
||||
};
|
||||
|
||||
struct bitmap;
|
||||
|
||||
int ssd1306_open(const struct ssd1306 *dev);
|
||||
int ssd1306_close(const struct ssd1306 *dev);
|
||||
int ssd1306_write(const struct ssd1306 *dev, const struct bitmap *bitmap);
|
||||
|
||||
#endif /* SSD1306_H_ */
|
Reference in New Issue
Block a user