-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work is done for today, ice cream time
- Loading branch information
Showing
6 changed files
with
358 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
****************************************************************************** | ||
* @file : hx711.h | ||
* @brief : HX711 library header file | ||
****************************************************************************** | ||
* @attention | ||
* | ||
* <h2><center> by leonek | ||
* have fun</center></h2> | ||
* | ||
* gnu gpl v3.0 licence forever!~ | ||
* | ||
****************************************************************************** | ||
*/ | ||
|
||
#ifndef HX711_H //we want to include library only once | ||
#define HX711_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
// all hxes | ||
typedef enum | ||
{ | ||
HX_A = 0, //top right | ||
HX_B = 1, //top left | ||
HX_C = 2, //bottom left | ||
HX_D = 3 //bottom right | ||
} HX_nr; | ||
|
||
void HX_begin(HX_nr module); | ||
uint32_t HX_read(HX_nr module); | ||
bool HX_check(HX_nr module); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
****************************************************************************** | ||
* @file : pca9685.h | ||
* @brief : PCA9685 PWM library header file | ||
****************************************************************************** | ||
* @attention | ||
* | ||
* <h2><center> by leonek | ||
* have fun</center></h2> | ||
* | ||
* gnu gpl v3.0 licence forever!~ | ||
* | ||
****************************************************************************** | ||
*/ | ||
|
||
#ifndef PCA9685_H //we want to include library only once | ||
#define PCA9685_H | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
uint8_t PCA_read8(uint8_t reg); | ||
void PCA_write8(uint8_t reg, uint8_t val); | ||
void PCA_reset(); | ||
void PCA_setBit(uint8_t reg, uint8_t bit, bool val); | ||
void PCA_sleepMode(bool s); | ||
void PCA_restartMode(bool s); | ||
void PCA_autoIncrement(bool s); | ||
void PCA_setFreq(int f); | ||
void PCA_setPWM(uint8_t channel, int ontime, int offtime); | ||
void PCA_setPin(uint8_t channel, int value); | ||
long map(long x, long in_min, long in_max, long out_min, long out_max); | ||
void PCA_setServoAngle(uint8_t channel, float angle); | ||
void PCA_begin(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
****************************************************************************** | ||
* @file : xh711.c | ||
* @brief : XH711 library source file | ||
****************************************************************************** | ||
* @attention | ||
* | ||
* <h2><center> by leonek | ||
* have fun</center></h2> | ||
* | ||
* gnu gpl v3.0 licence forever!~ | ||
* | ||
****************************************************************************** | ||
*/ | ||
#include <stdbool.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <math.h> | ||
#include "hx711.h" | ||
#include "gpio.h" | ||
#include "main.h" | ||
|
||
typedef struct | ||
{ | ||
GPIO_TypeDef* clk_port; | ||
uint16_t clk_pin; | ||
GPIO_TypeDef* data_port; | ||
uint16_t data_pin; | ||
} HX_ADC; | ||
|
||
static const HX_ADC HXes[] = | ||
{ | ||
{HX0_CLOCK_GPIO_Port, HX0_CLOCK_Pin, HX0_DATA_GPIO_Port, HX0_DATA_Pin}, | ||
{HX1_CLOCK_GPIO_Port, HX1_CLOCK_Pin, HX1_DATA_GPIO_Port, HX1_DATA_Pin}, | ||
{HX2_CLOCK_GPIO_Port, HX2_CLOCK_Pin, HX2_DATA_GPIO_Port, HX2_DATA_Pin}, | ||
{HX3_CLOCK_GPIO_Port, HX3_CLOCK_Pin, HX3_DATA_GPIO_Port, HX3_DATA_Pin} | ||
}; | ||
|
||
#define BITS_A_128 25 | ||
#define BITS_B_32 26 | ||
#define BITS_A_64 27 | ||
|
||
#define CLOCK_BITS BITS_A_128 | ||
|
||
void HX_begin(HX_nr module) | ||
{ | ||
while(HAL_GPIO_ReadPin(HXes[module].data_port, HXes[module].data_pin)); //wait til ready | ||
for(int x = 0; x < CLOCK_BITS; x++) | ||
{ | ||
HAL_GPIO_WritePin(HXes[module].data_port, HXes[module].data_pin, GPIO_PIN_SET); | ||
HAL_Delay(1); | ||
HAL_GPIO_WritePin(HXes[module].data_port, HXes[module].data_pin, GPIO_PIN_SET); | ||
HAL_Delay(0); | ||
} | ||
} | ||
|
||
//read | ||
uint32_t HX_read(HX_nr module) | ||
{ | ||
uint32_t result = 0; | ||
while(HAL_GPIO_ReadPin(HXes[module].data_port, HXes[module].data_pin)); //wait til ready | ||
|
||
for(int x = 0; x < CLOCK_BITS; x++) | ||
{ | ||
HAL_GPIO_WritePin(HXes[module].data_port, HXes[module].data_pin, GPIO_PIN_SET); | ||
if(x < 25) result |= HAL_GPIO_ReadPin(HXes[module].data_port, HXes[module].data_pin) << x; | ||
HAL_GPIO_WritePin(HXes[module].data_port, HXes[module].data_pin, GPIO_PIN_RESET); | ||
} | ||
return result; | ||
} | ||
|
||
//check the state | ||
bool HX_check(HX_nr module) | ||
{ | ||
if(HAL_GPIO_ReadPin(HXes[module].data_port, HXes[module].data_pin) == GPIO_PIN_SET) | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.