Patch by Vasilis Kaoutsis - thanks!:
* Fixed some warnings. * Style cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21774 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,32 +1,40 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2003, Thomas Kurschel
|
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
Part of DDC driver
|
Part of DDC driver
|
||||||
|
|
||||||
Main DDC communication
|
Main DDC communication
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <OS.h>
|
|
||||||
#include <KernelExport.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "ddc_int.h"
|
#include "ddc_int.h"
|
||||||
#include "ddc.h"
|
#include "ddc.h"
|
||||||
|
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
||||||
// number of retries to read ddc data
|
#include <KernelExport.h>
|
||||||
#define READ_RETRIES 4
|
#include <OS.h>
|
||||||
|
|
||||||
// verify checksum of ddc data
|
#include <stdlib.h>
|
||||||
// (some monitors have a broken checksum - bad luck for them)
|
|
||||||
static status_t verify_checksum( const uint8 *data, size_t len )
|
|
||||||
|
#define READ_RETRIES 4
|
||||||
|
// number of retries to read ddc data
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*! Verify checksum of ddc data
|
||||||
|
(some monitors have a broken checksum - bad luck for them)
|
||||||
|
*/
|
||||||
|
static status_t
|
||||||
|
verify_checksum(const uint8 *data, size_t len)
|
||||||
{
|
{
|
||||||
int i;
|
uint32 index;
|
||||||
uint8 sum = 0;
|
uint8 sum = 0;
|
||||||
uint8 all_or = 0;
|
uint8 all_or = 0;
|
||||||
|
|
||||||
for( i = 0; i < len; ++i, ++data ) {
|
for (index = 0; index < len; ++index, ++data) {
|
||||||
sum += *data;
|
sum += *data;
|
||||||
all_or |= *data;
|
all_or |= *data;
|
||||||
}
|
}
|
||||||
@@ -43,14 +51,17 @@ static status_t verify_checksum( const uint8 *data, size_t len )
|
|||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// read ddc2 data from monitor
|
|
||||||
static status_t ddc2_read( const i2c_bus *bus, int start, uint8 *buffer, size_t len )
|
//! Read ddc2 data from monitor
|
||||||
|
static status_t
|
||||||
|
ddc2_read(const i2c_bus *bus, int start, uint8 *buffer, size_t len)
|
||||||
{
|
{
|
||||||
uint8 write_buffer[2];
|
uint8 write_buffer[2];
|
||||||
i2c_timing timing;
|
i2c_timing timing;
|
||||||
int i;
|
int i;
|
||||||
status_t res;
|
status_t res = B_OK;
|
||||||
|
|
||||||
write_buffer[0] = start & 0xff;
|
write_buffer[0] = start & 0xff;
|
||||||
write_buffer[1] = (start >> 8) & 0xff;
|
write_buffer[1] = (start >> 8) & 0xff;
|
||||||
@@ -78,11 +89,14 @@ static status_t ddc2_read( const i2c_bus *bus, int start, uint8 *buffer, size_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// reading VDIF has not been tested.
|
/*!
|
||||||
// it seems that almost noone supports VDIF which makes testing hard,
|
Reading VDIF has not been tested.
|
||||||
// but what's the point anyway?
|
it seems that almost noone supports VDIF which makes testing hard,
|
||||||
|
but what's the point anyway?
|
||||||
|
*/
|
||||||
#if 0
|
#if 0
|
||||||
static status_t ddc2_read_vdif( const i2c_bus *bus, int start,
|
static status_t
|
||||||
|
ddc2_read_vdif(const i2c_bus *bus, int start,
|
||||||
void **vdif, size_t *vdif_len)
|
void **vdif, size_t *vdif_len)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
@@ -118,8 +132,10 @@ static status_t ddc2_read_vdif( const i2c_bus *bus, int start,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// read EDID and VDIF from monitor via ddc2
|
|
||||||
status_t ddc2_read_edid1( const i2c_bus *bus, edid1_info *edid,
|
//! Read EDID and VDIF from monitor via ddc2
|
||||||
|
status_t
|
||||||
|
ddc2_read_edid1(const i2c_bus *bus, edid1_info *edid,
|
||||||
void **vdif, size_t *vdif_len)
|
void **vdif, size_t *vdif_len)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2003, Thomas Kurschel
|
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef DDC_INT_H
|
||||||
|
#define DDC_INT_H
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
Part of DDC driver
|
Part of DDC driver
|
||||||
|
|
||||||
Internal header
|
Internal header
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// no dprintf in user space, but if you know the trick ;)
|
|
||||||
void _sPrintf(const char *format, ...);
|
void _sPrintf(const char *format, ...);
|
||||||
|
// no dprintf in user space, but if you know the trick ;)
|
||||||
|
|
||||||
//bool set_dprintf_enabled(bool); /* returns old enable flag */
|
//bool set_dprintf_enabled(bool); /* returns old enable flag */
|
||||||
|
|
||||||
#define dprintf _sPrintf
|
#define dprintf _sPrintf
|
||||||
@@ -21,3 +27,5 @@ void _sPrintf(const char *format, ...);
|
|||||||
#define DEBUG_MSG_PREFIX "DDC "
|
#define DEBUG_MSG_PREFIX "DDC "
|
||||||
|
|
||||||
#include "debug_ext.h"
|
#include "debug_ext.h"
|
||||||
|
|
||||||
|
#endif // DDC_INT_H
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, Thomas Kurschel. All Rights Reserved.
|
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Part of DDC driver
|
Part of DDC driver
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
#include "edid.h"
|
#include "edid.h"
|
||||||
|
|
||||||
#include <KernelExport.h>
|
#include <KernelExport.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -89,12 +91,15 @@ decode_std_timing(edid1_std_timing *timing, const edid1_std_timing_raw *raw)
|
|||||||
case 0:
|
case 0:
|
||||||
timing->v_size = timing->h_size;
|
timing->v_size = timing->h_size;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
timing->v_size = timing->h_size * 3 / 4;
|
timing->v_size = timing->h_size * 3 / 4;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
timing->v_size = timing->h_size * 4 / 5;
|
timing->v_size = timing->h_size * 4 / 5;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
timing->v_size = timing->h_size * 9 / 16;
|
timing->v_size = timing->h_size * 9 / 16;
|
||||||
break;
|
break;
|
||||||
@@ -191,21 +196,26 @@ decode_detailed_monitor( edid1_detailed_monitor *monitor,
|
|||||||
copy_str( monitor->data.serial_number,
|
copy_str( monitor->data.serial_number,
|
||||||
raw->extra.data.serial_number, EDID1_EXTRA_STRING_LEN );
|
raw->extra.data.serial_number, EDID1_EXTRA_STRING_LEN );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case edid1_ascii_data:
|
case edid1_ascii_data:
|
||||||
copy_str( monitor->data.ascii_data,
|
copy_str( monitor->data.ascii_data,
|
||||||
raw->extra.data.ascii_data, EDID1_EXTRA_STRING_LEN );
|
raw->extra.data.ascii_data, EDID1_EXTRA_STRING_LEN );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case edid1_monitor_ranges:
|
case edid1_monitor_ranges:
|
||||||
monitor->data.monitor_range = raw->extra.data.monitor_range;
|
monitor->data.monitor_range = raw->extra.data.monitor_range;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case edid1_monitor_name:
|
case edid1_monitor_name:
|
||||||
copy_str( monitor->data.monitor_name,
|
copy_str( monitor->data.monitor_name,
|
||||||
raw->extra.data.monitor_name, EDID1_EXTRA_STRING_LEN );
|
raw->extra.data.monitor_name, EDID1_EXTRA_STRING_LEN );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case edid1_add_colour_pointer:
|
case edid1_add_colour_pointer:
|
||||||
decode_whitepoint( monitor->data.whitepoint,
|
decode_whitepoint( monitor->data.whitepoint,
|
||||||
&raw->extra.data.whitepoint );
|
&raw->extra.data.whitepoint );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case edid1_add_std_timing:
|
case edid1_add_std_timing:
|
||||||
for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
|
for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
|
||||||
decode_std_timing(&monitor->data.std_timing[j],
|
decode_std_timing(&monitor->data.std_timing[j],
|
||||||
@@ -224,7 +234,7 @@ decode_detailed_monitor( edid1_detailed_monitor *monitor,
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
//! main function to decode edid data
|
//! Main function to decode edid data
|
||||||
void
|
void
|
||||||
edid_decode(edid1_info *edid, const edid1_raw *raw)
|
edid_decode(edid1_info *edid, const edid1_raw *raw)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,11 +3,13 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Part of DDC driver
|
Part of DDC driver
|
||||||
Dumps EDID content
|
Dumps EDID content
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "edid.h"
|
#include "edid.h"
|
||||||
#if !defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
#if !defined(_KERNEL_MODE) && !defined(_BOOT_MODE)
|
||||||
# include "ddc_int.h"
|
# include "ddc_int.h"
|
||||||
@@ -91,10 +93,13 @@ edid_dump(edid1_info *edid)
|
|||||||
case edid1_serial_number:
|
case edid1_serial_number:
|
||||||
dprintf("Serial Number: %s\n", monitor->data.serial_number);
|
dprintf("Serial Number: %s\n", monitor->data.serial_number);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case edid1_ascii_data:
|
case edid1_ascii_data:
|
||||||
dprintf(" %s\n", monitor->data.serial_number);
|
dprintf(" %s\n", monitor->data.serial_number);
|
||||||
break;
|
break;
|
||||||
case edid1_monitor_ranges: {
|
|
||||||
|
case edid1_monitor_ranges:
|
||||||
|
{
|
||||||
edid1_monitor_range monitor_range = monitor->data.monitor_range;
|
edid1_monitor_range monitor_range = monitor->data.monitor_range;
|
||||||
|
|
||||||
dprintf("Horizontal frequency range = %d..%d kHz\n",
|
dprintf("Horizontal frequency range = %d..%d kHz\n",
|
||||||
@@ -104,10 +109,13 @@ edid_dump(edid1_info *edid)
|
|||||||
dprintf("Maximum pixel clock = %d MHz\n", (uint16)monitor_range.max_clock * 10);
|
dprintf("Maximum pixel clock = %d MHz\n", (uint16)monitor_range.max_clock * 10);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case edid1_monitor_name:
|
case edid1_monitor_name:
|
||||||
dprintf("Monitor Name: %s\n", monitor->data.serial_number);
|
dprintf("Monitor Name: %s\n", monitor->data.serial_number);
|
||||||
break;
|
break;
|
||||||
case edid1_add_colour_pointer: {
|
|
||||||
|
case edid1_add_colour_pointer:
|
||||||
|
{
|
||||||
for (j = 0; j < EDID1_NUM_EXTRA_WHITEPOINTS; ++j) {
|
for (j = 0; j < EDID1_NUM_EXTRA_WHITEPOINTS; ++j) {
|
||||||
edid1_whitepoint *whitepoint = &monitor->data.whitepoint[j];
|
edid1_whitepoint *whitepoint = &monitor->data.whitepoint[j];
|
||||||
|
|
||||||
@@ -122,7 +130,9 @@ edid_dump(edid1_info *edid)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case edid1_add_std_timing: {
|
|
||||||
|
case edid1_add_std_timing:
|
||||||
|
{
|
||||||
for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
|
for (j = 0; j < EDID1_NUM_EXTRA_STD_TIMING; ++j) {
|
||||||
edid1_std_timing *timing = &monitor->data.std_timing[j];
|
edid1_std_timing *timing = &monitor->data.std_timing[j];
|
||||||
|
|
||||||
@@ -135,7 +145,9 @@ edid_dump(edid1_info *edid)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case edid1_is_detailed_timing: {
|
|
||||||
|
case edid1_is_detailed_timing:
|
||||||
|
{
|
||||||
edid1_detailed_timing *timing = &monitor->data.detailed_timing;
|
edid1_detailed_timing *timing = &monitor->data.detailed_timing;
|
||||||
|
|
||||||
dprintf("Additional Video Mode:\n");
|
dprintf("Additional Video Mode:\n");
|
||||||
|
|||||||
@@ -1,24 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
Copyright (c) 2003, Thomas Kurschel
|
* Copyright 2003, Thomas Kurschel. All Rights Reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
Part of DDC driver
|
Part of DDC driver
|
||||||
|
|
||||||
I2C protocoll
|
I2C protocoll
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <OS.h>
|
#include "ddc_int.h"
|
||||||
#include <KernelExport.h>
|
|
||||||
|
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
|
||||||
#include "ddc_int.h"
|
#include <KernelExport.h>
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
|
||||||
// there's no spin in user space, but we need it to wait a couple
|
/*!
|
||||||
// of microseconds only
|
There's no spin in user space, but we need it to wait a couple
|
||||||
// (in this case, snooze has much too much overhead)
|
of microseconds only
|
||||||
void spin( bigtime_t delay )
|
(in this case, snooze has much too much overhead)
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
spin(bigtime_t delay)
|
||||||
{
|
{
|
||||||
bigtime_t start_time = system_time();
|
bigtime_t start_time = system_time();
|
||||||
|
|
||||||
@@ -27,8 +31,9 @@ void spin( bigtime_t delay )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// wait until slave releases clock signal ("clock stretching")
|
//! Wait until slave releases clock signal ("clock stretching")
|
||||||
static status_t wait_for_clk( const i2c_bus *bus, const i2c_timing *timing,
|
static status_t
|
||||||
|
wait_for_clk(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
bigtime_t timeout)
|
bigtime_t timeout)
|
||||||
{
|
{
|
||||||
bigtime_t start_time;
|
bigtime_t start_time;
|
||||||
@@ -53,8 +58,9 @@ static status_t wait_for_clk( const i2c_bus *bus, const i2c_timing *timing,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// send start or repeated start condition
|
//! Send start or repeated start condition
|
||||||
static status_t send_start_condition( const i2c_bus *bus, const i2c_timing *timing )
|
static status_t
|
||||||
|
send_start_condition(const i2c_bus *bus, const i2c_timing *timing)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
@@ -76,8 +82,9 @@ static status_t send_start_condition( const i2c_bus *bus, const i2c_timing *timi
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// send stop condition
|
//! Send stop condition
|
||||||
static status_t send_stop_condition( const i2c_bus *bus, const i2c_timing *timing )
|
static status_t
|
||||||
|
send_stop_condition(const i2c_bus *bus, const i2c_timing *timing)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
@@ -103,8 +110,9 @@ static status_t send_stop_condition( const i2c_bus *bus, const i2c_timing *timin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// send one bit
|
//! Send one bit
|
||||||
static status_t send_bit( const i2c_bus *bus, const i2c_timing *timing, bool bit, int timeout )
|
static status_t
|
||||||
|
send_bit(const i2c_bus *bus, const i2c_timing *timing, bool bit, int timeout)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
@@ -128,8 +136,9 @@ static status_t send_bit( const i2c_bus *bus, const i2c_timing *timing, bool bit
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// send acknowledge and wait for reply
|
//! Send acknowledge and wait for reply
|
||||||
static status_t send_acknowledge( const i2c_bus *bus, const i2c_timing *timing )
|
static status_t
|
||||||
|
send_acknowledge(const i2c_bus *bus, const i2c_timing *timing)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
bigtime_t start_time;
|
bigtime_t start_time;
|
||||||
@@ -177,8 +186,9 @@ static status_t send_acknowledge( const i2c_bus *bus, const i2c_timing *timing )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// send byte and wait for acknowledge if <ackowledge> is true
|
//! Send byte and wait for acknowledge if <ackowledge> is true
|
||||||
static status_t send_byte( const i2c_bus *bus, const i2c_timing *timing,
|
static status_t
|
||||||
|
send_byte(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
uint8 byte, bool acknowledge)
|
uint8 byte, bool acknowledge)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -200,9 +210,11 @@ static status_t send_byte( const i2c_bus *bus, const i2c_timing *timing,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send slave address, obeying 10-bit addresses and general call addresses
|
|
||||||
static status_t send_slave_address( const i2c_bus *bus,
|
//! Send slave address, obeying 10-bit addresses and general call addresses
|
||||||
const i2c_timing *timing, int slave_address, bool is_write )
|
static status_t
|
||||||
|
send_slave_address( const i2c_bus *bus, const i2c_timing *timing,
|
||||||
|
int slave_address, bool is_write )
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
|
|
||||||
@@ -221,24 +233,24 @@ static status_t send_slave_address( const i2c_bus *bus,
|
|||||||
// - 1111 0xxx - 10 bit address (second byte contains remaining 8 bits)
|
// - 1111 0xxx - 10 bit address (second byte contains remaining 8 bits)
|
||||||
|
|
||||||
// the lsb is 0 for write and 1 for read (except for general call address)
|
// the lsb is 0 for write and 1 for read (except for general call address)
|
||||||
if( (slave_address & 0xff) != 0 &&
|
if ((slave_address & 0xff) != 0 && (slave_address & 0xf8) != 0xf0)
|
||||||
(slave_address & 0xf8) != 0xf0 )
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|
||||||
// send second byte if required
|
|
||||||
return send_byte(bus, timing, slave_address >> 8, true);
|
return send_byte(bus, timing, slave_address >> 8, true);
|
||||||
|
// send second byte if required
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// receive one bit
|
//! Receive one bit
|
||||||
static status_t receive_bit( const i2c_bus *bus, const i2c_timing *timing,
|
static status_t
|
||||||
|
receive_bit(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
bool *bit, int timeout)
|
bool *bit, int timeout)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
int clk, data;
|
int clk, data;
|
||||||
|
|
||||||
// release clock
|
|
||||||
bus->set_signals(bus->cookie, 1, 1);
|
bus->set_signals(bus->cookie, 1, 1);
|
||||||
|
// release clock
|
||||||
|
|
||||||
// wait for slave to raise clock
|
// wait for slave to raise clock
|
||||||
res = wait_for_clk(bus, timing, timeout);
|
res = wait_for_clk(bus, timing, timeout);
|
||||||
@@ -247,23 +259,30 @@ static status_t receive_bit( const i2c_bus *bus, const i2c_timing *timing,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sample data
|
|
||||||
bus->get_signals(bus->cookie, &clk, &data);
|
bus->get_signals(bus->cookie, &clk, &data);
|
||||||
// leave clock high for minimal time
|
// sample data
|
||||||
|
|
||||||
spin(timing->high);
|
spin(timing->high);
|
||||||
// pull clock low so slave waits for us before next bit
|
// leave clock high for minimal time
|
||||||
|
|
||||||
bus->set_signals(bus->cookie, 0, 1);
|
bus->set_signals(bus->cookie, 0, 1);
|
||||||
|
// pull clock low so slave waits for us before next bit
|
||||||
|
|
||||||
|
spin(timing->f + timing->low);
|
||||||
// let it settle and leave it low for minimal time
|
// let it settle and leave it low for minimal time
|
||||||
// to make sure slave has finished bit transmission too
|
// to make sure slave has finished bit transmission too
|
||||||
spin( timing->f + timing->low);
|
|
||||||
|
|
||||||
*bit = data;
|
*bit = data;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// receive byte
|
|
||||||
// send positive acknowledge afterwards if <acknowledge> is true, else send negative one
|
/*! receive byte
|
||||||
static status_t receive_byte( const i2c_bus *bus, const i2c_timing *timing,
|
Send positive acknowledge afterwards if <acknowledge> is true,
|
||||||
|
else send negative one
|
||||||
|
*/
|
||||||
|
static status_t
|
||||||
|
receive_byte(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
uint8 *res_byte, bool acknowledge)
|
uint8 *res_byte, bool acknowledge)
|
||||||
{
|
{
|
||||||
uint8 byte = 0;
|
uint8 byte = 0;
|
||||||
@@ -291,8 +310,10 @@ static status_t receive_byte( const i2c_bus *bus, const i2c_timing *timing,
|
|||||||
return send_bit(bus, timing, acknowledge ? 0 : 1, timing->bit_timeout);
|
return send_bit(bus, timing, acknowledge ? 0 : 1, timing->bit_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send multiple bytes
|
|
||||||
static status_t send_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
//! Send multiple bytes
|
||||||
|
static status_t
|
||||||
|
send_bytes(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
const uint8 *write_buffer, ssize_t write_len)
|
const uint8 *write_buffer, ssize_t write_len)
|
||||||
{
|
{
|
||||||
SHOW_FLOW( 3, "len=%ld", write_len );
|
SHOW_FLOW( 3, "len=%ld", write_len );
|
||||||
@@ -308,8 +329,10 @@ static status_t send_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// receive multiple bytes
|
|
||||||
static status_t receive_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
//! Receive multiple bytes
|
||||||
|
static status_t
|
||||||
|
receive_bytes(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
uint8 *read_buffer, ssize_t read_len)
|
uint8 *read_buffer, ssize_t read_len)
|
||||||
{
|
{
|
||||||
SHOW_FLOW(3, "len=%ld", read_len);
|
SHOW_FLOW(3, "len=%ld", read_len);
|
||||||
@@ -325,10 +348,11 @@ static status_t receive_bytes( const i2c_bus *bus, const i2c_timing *timing,
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// combined i2c send+receive format
|
|
||||||
status_t i2c_send_receive( const i2c_bus *bus, const i2c_timing *timing,
|
//! Combined i2c send+receive format
|
||||||
int slave_address,
|
status_t
|
||||||
const uint8 *write_buffer, size_t write_len,
|
i2c_send_receive(const i2c_bus *bus, const i2c_timing *timing,
|
||||||
|
int slave_address, const uint8 *write_buffer, size_t write_len,
|
||||||
uint8 *read_buffer, size_t read_len)
|
uint8 *read_buffer, size_t read_len)
|
||||||
{
|
{
|
||||||
status_t res;
|
status_t res;
|
||||||
@@ -366,9 +390,9 @@ err:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// timining for 100kHz bus (fractional parts are rounded up)
|
|
||||||
i2c_timing i2c_timing_100k =
|
//! Timining for 100kHz bus (fractional parts are rounded up)
|
||||||
{
|
i2c_timing i2c_timing_100k = {
|
||||||
buf : 5,
|
buf : 5,
|
||||||
hd_sta : 4,
|
hd_sta : 4,
|
||||||
low : 5,
|
low : 5,
|
||||||
@@ -390,8 +414,7 @@ i2c_timing i2c_timing_100k =
|
|||||||
|
|
||||||
// timing for 400 kHz bus
|
// timing for 400 kHz bus
|
||||||
// (argh! heavy up-rounding here)
|
// (argh! heavy up-rounding here)
|
||||||
i2c_timing i2c_timing_400k =
|
i2c_timing i2c_timing_400k = {
|
||||||
{
|
|
||||||
buf : 2,
|
buf : 2,
|
||||||
hd_sta : 1,
|
hd_sta : 1,
|
||||||
low : 2,
|
low : 2,
|
||||||
@@ -411,12 +434,16 @@ i2c_timing i2c_timing_400k =
|
|||||||
ack_timeout : 2
|
ack_timeout : 2
|
||||||
};
|
};
|
||||||
|
|
||||||
void i2c_get100k_timing( i2c_timing *timing )
|
|
||||||
|
void
|
||||||
|
i2c_get100k_timing(i2c_timing *timing)
|
||||||
{
|
{
|
||||||
*timing = i2c_timing_100k;
|
*timing = i2c_timing_100k;
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_get400k_timing( i2c_timing *timing )
|
|
||||||
|
void
|
||||||
|
i2c_get400k_timing(i2c_timing *timing)
|
||||||
{
|
{
|
||||||
*timing = i2c_timing_400k;
|
*timing = i2c_timing_400k;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user