Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i2c): add baud rate setting functionality #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions c/common/i2cdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>

#include "i2cdriver.h"

Expand Down Expand Up @@ -323,6 +324,20 @@ void i2c_getstatus(I2CDriver *sd)
sd->mode = mode[0];
}

bool i2c_setbaud(I2CDriver *sd, unsigned int kbaud)
{
if (kbaud == sd->speed) {
return true;
}
if ((kbaud != 100) || (kbaud != 400)) {
return false;
}
uint8_t ch = (kbaud == 100)?'1':'4';
writeToSerialPort(sd->port, &ch, 1);
i2c_getstatus(sd);
return (bool)(sd->speed == kbaud);;
}

void i2c_scan(I2CDriver *sd, uint8_t devices[128])
{
charCommand(sd, 'd');
Expand Down
3 changes: 3 additions & 0 deletions c/common/i2cdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define I2CDRIVER_H

#include <stdint.h>
#include <stdbool.h>

#if defined(WIN32)
#include <windows.h>
Expand Down Expand Up @@ -36,6 +37,8 @@ void i2c_read(I2CDriver *sd, uint8_t bytes[], size_t nn);
int i2c_start(I2CDriver *sd, uint8_t dev, uint8_t op);
void i2c_stop(I2CDriver *sd);

bool i2c_setbaud(I2CDriver *sd, int kbaud);

void i2c_monitor(I2CDriver *sd, int enable);
void i2c_capture(I2CDriver *sd);

Expand Down