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

[Firmware][I2C MultiPlexer] implement interface to use I2C MultiPlexer #658

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
******************************************************************************
* File Name : switcher.cpp
* Description : I2C Multi Plexer Interface
******************************************************************************
*/

#include "switcher.h"

namespace I2C_MultiPlexer
{
namespace
{
I2C_HandleTypeDef* hi2c_;

uint8_t hub_address_ = 0x70; // the default I2C adress of PCA9547D. TODO: reconfigurable
};

void init(I2C_HandleTypeDef* hi2c)
{
hi2c_ = hi2c;
}

bool changeChannel(uint8_t ch)
{
uint8_t val[1];
val[0] = ch & 0x07; // assign the channel
val[0] = ch | 0x08; // enable switch the channel

int i2c_status = HAL_I2C_Master_Transmit(hi2c_, hub_address_, val, 1, 100);

if(i2c_status == HAL_OK) return true;
else return false;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
******************************************************************************
* File Name : switcher.h
* Description : I2C Multi Plexer Interface
******************************************************************************
*/

#ifndef __cplusplus
#error "Please define __cplusplus, because this is a c++ based file "
#endif

#ifndef __I2C_MULTIPLEXER_H
#define __I2C_MULTIPLEXER_H

#include "config.h"

namespace I2C_MultiPlexer
{
void init(I2C_HandleTypeDef* hi2c);
bool changeChannel(uint8_t ch);
};



#endif
Loading