[refactor] prepare for link gen
This commit is contained in:
@@ -5,20 +5,19 @@ static uint32_t pot_value[MCP41X_RES_MAX] = {10000, 50000, 100000};
|
||||
|
||||
static void mcp41x_transmit(mcp41x_handle_t *hpot, uint8_t *data)
|
||||
{
|
||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_RESET);
|
||||
hpot->hcs->cs_on(hpot->hcs);
|
||||
HAL_SPI_Transmit(hpot->hspi, data, 2, HAL_MAX_DELAY);
|
||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_SET);
|
||||
hpot->hcs->cs_off(hpot->hcs);
|
||||
}
|
||||
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin, mcp41x_res_t res)
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, cs_handle_t *hcs, mcp41x_res_t res)
|
||||
{
|
||||
hpot->hspi = hspi;
|
||||
hpot->cs_port = cs_port;
|
||||
hpot->cs_pin = cs_pin;
|
||||
hpot->hcs = hcs;
|
||||
hpot->max_res = res;
|
||||
hpot->dir = MCP41X_ATOB;
|
||||
|
||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_SET);
|
||||
hpot->hcs->cs_off(hcs);
|
||||
}
|
||||
|
||||
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "spi_cs_if.h"
|
||||
|
||||
#define MCP41X_C1 5
|
||||
#define MCP41X_C0 4
|
||||
#define MCP41X_P1 1
|
||||
@@ -36,11 +38,10 @@ typedef struct
|
||||
uint8_t value;
|
||||
|
||||
SPI_HandleTypeDef *hspi;
|
||||
GPIO_TypeDef *cs_port;
|
||||
uint16_t cs_pin;
|
||||
cs_handle_t *hcs;
|
||||
} mcp41x_handle_t;
|
||||
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin, mcp41x_res_t res);
|
||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, cs_handle_t *hcs, mcp41x_res_t res);
|
||||
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value);
|
||||
void mcp41x_setVolume(mcp41x_handle_t *hpot, uint8_t volume);
|
||||
uint8_t mcp41x_getVolume(mcp41x_handle_t *hpot);
|
||||
|
||||
Reference in New Issue
Block a user