Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
220 changes: 220 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#################
## SparkFun Useful stuff
#################

## AVR Development
*.eep
*.elf
*.lst
*.lss
*.sym
*.d
*.o
*.srec
*.map

## Notepad++ backup files
*.bak

## BOM files
*bom*

## VSCode directories
.vscode

#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#############
## Eagle
#############

# Ignore the board and schematic backup files and lock files
*.b#?
*.s#?
*.l#?
*.lck


#############
## KiCad
#############

*cache.lib
*.kicad_pcb-bak
*.net
*.gbr
*.drl


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp

# ReSharper is a .NET coding add-in
_ReSharper*

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML


############
## Windows
############

# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini


#############
## Mac OS
#############

.DS_Store


#############
## Linux
#############

# backup files (*.bak on Win)
*~


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on changing the .gitignore to include only relevant things for this repo? I'm not really a fan of continually copying "the one master .gitignore" for all projects. What the heck even is .mr.develop.cfg?

File renamed without changes.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name=SparkFun Toolkit
version=0.1.0
author=SparkFun Electronics
maintainer=SparkFun Electronics
sentence=A utility library that other SparkFun libraries can take advantage of.
sentence=A generic communications utility library that other SparkFun libraries can take advantage of.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason it's called "Toolkit" is because Kirk was thinking about expanding it to do more than just communication at some point.

paragraph=
category=Other
url=https://github.com/sparkfun/SparkFun_Toolkit
Expand Down
11 changes: 10 additions & 1 deletion src/SparkFun_Toolkit.h
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// Code!
/*
SPDX-License-Identifier: MIT

Copyright (c) 2023 SparkFun Electronics
*/

#pragma once

#include "sfe_i2c_arduino.h"
// #include "sfe_spi_arduino.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just #include "sfe_bus.h"?

112 changes: 60 additions & 52 deletions src/sfe_bus.h
Original file line number Diff line number Diff line change
@@ -1,63 +1,71 @@
/*
sfe_bus.h
The MIT License (MIT)
Copyright (c) 2022 SparkFun Electronics
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions: The
above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The following virtual class provides an abstract communication interface.
SPDX-License-Identifier: MIT
Copyright (c) 2023 SparkFun Electronics
A pure virtual base class for implementing a common communication interface
in SparkFun products.
*/

#pragma once

#include <cstdint>
#include <stdint.h>

// Error and warning codes
#define SFE_BUS_OK 0
#define SFE_BUS_E_UNKNOWN -1
#define SFE_BUS_E_NULL_PTR -2
#define SFE_BUS_E_TIMEOUT -3
#define SFE_BUS_E_NO_RESPONSE -4
#define SFE_BUS_E_DATA_TOO_LONG -5
#define SFE_BUS_E_NULL_DEV_SETTINGS -6
#define SFE_BUS_E_NULL_DATA_BUFFER -7
#define SFE_BUS_W_UNKNOWN 1
#define SFE_BUS_W_UNDER_READ 2
#define SFE_BUS_W_NOT_ENABLED 3

// To repeatedly use this toolkit, you may need to wrap this class in a namespace.
// namespace sfe_XXX {
/// @brief An abstract Bus address class for enabling multiple types of addresses.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest changing to something like "An abstract class for specifying parameters required to communicate with a particular device on a bus"

class SFEBusDevSettings{}; // Nothing to see here...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: thoughts on Params instead of Settings?


// The following abstract class is used an interface for upstream implementation.
class SfeBus
/// @brief An abstract interface for a communication bus
class SFEBus
{
public:
/// @brief A simple ping of the device at the given address.
/// @param devAddr Address of the device
virtual bool ping(uint8_t devAddr) = 0;

/// @brief Write a single byte to the given register
/// @param devAddr The device's I2C address.
/// @param devReg The device's register's address.
/// @param data Data to write.
/// @brief returns true on successful execution.
virtual bool writeRegisterByte(uint8_t devAddr, uint8_t devReg, uint8_t data) = 0;

/// @brief Writes a number of bytes starting at the given register's address.
/// @param devAddr The device's I2C address.
/// @param devReg The device's register's address.
/// @param data Data to write.
/// @brief returns true on successful execution.
virtual int writeRegisterRegion(uint8_t devAddr, uint8_t devReg, const uint8_t *data, uint16_t length) = 0;

/// @brief Reads a block of data from the given register.
/// @param devAddr The device's I2C address.
/// @param devReg The device's register's address.
/// @param data Data to write.
/// @brief returns true on successful execution.
virtual int readRegisterRegion(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t numBytes) = 0;
};
/// @brief Begin bus.
/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t begin(void) = 0;

/// @brief End bus.
/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t end(void) = 0;

//};
/// @brief Writes a number of bytes starting at the given register address.
/// @param devSettings Settings of the device.
/// @param regAddr The first register address to write to.
/// @param data Data buffer to write to registers.
/// @param numBytes Number of bytes to write.
/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t writeRegisterBytes(const SFEBusDevSettings *devSettings, const uint8_t regAddr, const uint8_t *data, const uint32_t numBytes) = 0;

/// @brief Reads a number of bytes starting at the given register address.
/// @param devSettings Settings of the device.
/// @param regAddr The first register address to read from.
/// @param data Data buffer to read from registers.
/// @param numBytes Number of bytes to read.
/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t readRegisterBytes(const SFEBusDevSettings *devSettings, const uint8_t regAddr, uint8_t *data, const uint32_t numBytes) = 0;

/// @brief Writes a number of bytes to a device that doesn't use registers for communications.
/// @param devSettings Settings of the device.
/// @param data Data buffer to read from registers.
/// @param numBytes Number of bytes to read.
Comment on lines +60 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write, not read

/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t writeBytes(const SFEBusDevSettings *devSettings, const uint8_t *data, const uint32_t numBytes) = 0;

/// @brief Reads a number of bytes to a device that doesn't use registers for communications.
/// @param devSettings Settings of the device.
/// @param data Data buffer to read from registers.
/// @param numBytes Number of bytes to read.
/// @return 0 for success, negative for failure, positive for warning.
virtual int8_t readBytes(const SFEBusDevSettings *devSettings, uint8_t *data, const uint32_t numBytes) = 0;
};
Loading