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

Put all GPIO defines in gpio_bitaxe.h #566

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions components/asic/bm1366.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gpio_bitaxe.h"

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM1366_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -318,13 +317,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
// reset the BM1366 via the RTS line
static void _reset(void)
{
gpio_set_level(BM1366_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);

// set the gpio pin high
gpio_set_level(BM1366_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand All @@ -344,8 +343,8 @@ uint8_t BM1366_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, SERIAL_BUF_SIZE);

esp_rom_gpio_pad_select_gpio(BM1366_RST_PIN);
gpio_set_direction(BM1366_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

// reset the bm1366
_reset();
Expand Down
11 changes: 5 additions & 6 deletions components/asic/bm1368.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gpio_bitaxe.h"

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM1368_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -121,9 +120,9 @@ void BM1368_set_version_mask(uint32_t version_mask)

static void _reset(void)
{
gpio_set_level(BM1368_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
gpio_set_level(BM1368_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);
vTaskDelay(100 / portTICK_PERIOD_MS);
}

Expand Down Expand Up @@ -242,8 +241,8 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, CHUNK_SIZE);

esp_rom_gpio_pad_select_gpio(BM1368_RST_PIN);
gpio_set_direction(BM1368_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

_reset();

Expand Down
11 changes: 5 additions & 6 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "gpio_bitaxe.h"

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BM1370_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -329,13 +328,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
// reset the BM1370 via the RTS line
static void _reset(void)
{
gpio_set_level(BM1370_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);

// set the gpio pin high
gpio_set_level(BM1370_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand All @@ -355,8 +354,8 @@ uint8_t BM1370_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, SERIAL_BUF_SIZE);

esp_rom_gpio_pad_select_gpio(BM1370_RST_PIN);
gpio_set_direction(BM1370_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

// reset the bm1370
_reset();
Expand Down
11 changes: 5 additions & 6 deletions components/asic/bm1397.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "gpio_bitaxe.h"

#include "serial.h"
#include "bm1397.h"
Expand All @@ -15,8 +16,6 @@
#include "mining.h"
#include "global_state.h"

#define BM1397_RST_PIN GPIO_NUM_1

#define TYPE_JOB 0x20
#define TYPE_CMD 0x40

Expand Down Expand Up @@ -278,13 +277,13 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
// reset the BM1397 via the RTS line
static void _reset(void)
{
gpio_set_level(BM1397_RST_PIN, 0);
gpio_set_level(GPIO_ASIC_RESET, 0);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);

// set the gpio pin high
gpio_set_level(BM1397_RST_PIN, 1);
gpio_set_level(GPIO_ASIC_RESET, 1);

// delay for 100ms
vTaskDelay(100 / portTICK_PERIOD_MS);
Expand All @@ -296,8 +295,8 @@ uint8_t BM1397_init(uint64_t frequency, uint16_t asic_count)

memset(asic_response_buffer, 0, SERIAL_BUF_SIZE);

esp_rom_gpio_pad_select_gpio(BM1397_RST_PIN);
gpio_set_direction(BM1397_RST_PIN, GPIO_MODE_OUTPUT);
esp_rom_gpio_pad_select_gpio(GPIO_ASIC_RESET);
gpio_set_direction(GPIO_ASIC_RESET, GPIO_MODE_OUTPUT);

// reset the bm1397
_reset();
Expand Down
1 change: 0 additions & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ SRCS
"fonts.c"
"i2c_bitaxe.c"
"INA260.c"
"led_controller.c"
"main.c"
"nvs_config.c"
"oled.c"
Expand Down
11 changes: 11 additions & 0 deletions main/gpio_bitaxe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef GPIO_BITAXE_H_
Copy link
Collaborator

Choose a reason for hiding this comment

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

My only comment is that it feels backwards that components would depend on a header in the app (main).

#define GPIO_BITAXE_H_

#define GPIO_BUTTON_BOOT GPIO_NUM_0
#define GPIO_ASIC_RESET GPIO_NUM_1
#define GPIO_ASIC_ENABLE GPIO_NUM_10
#define GPIO_PLUG_SENSE GPIO_NUM_12
#define GPIO_I2C_SDA GPIO_NUM_47
#define GPIO_I2C_SCL GPIO_NUM_48

#endif /* GPIO_BITAXE_H_ */
7 changes: 3 additions & 4 deletions main/i2c_bitaxe.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "esp_event.h"
#include "esp_log.h"
#include "i2c_bitaxe.h"
#include "gpio_bitaxe.h"

#define I2C_MASTER_SCL_IO 48 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO 47 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */

#define I2C_MASTER_NUM 0 /*!< I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip */
Expand All @@ -22,8 +21,8 @@ esp_err_t i2c_bitaxe_init(void)
i2c_master_bus_config_t i2c_bus_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_MASTER_NUM,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = GPIO_I2C_SCL,
.sda_io_num = GPIO_I2C_SDA,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
Expand Down
122 changes: 0 additions & 122 deletions main/led_controller.c

This file was deleted.

8 changes: 0 additions & 8 deletions main/led_controller.h

This file was deleted.

13 changes: 6 additions & 7 deletions main/self_test/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
#include "vcore.h"
#include "utils.h"
#include "TPS546.h"
#include "gpio_bitaxe.h"


#define BUTTON_BOOT GPIO_NUM_0
#define LONG_PRESS_DURATION_MS 2000 // Define what constitutes a long press
#define ESP_INTR_FLAG_DEFAULT 0 //wtf is this for esp-idf?

Expand Down Expand Up @@ -189,8 +188,8 @@ esp_err_t test_voltage_regulator(GlobalState * GLOBAL_STATE) {
case DEVICE_ULTRA:
case DEVICE_SUPRA:
// turn ASIC on
gpio_set_direction(GPIO_NUM_10, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_NUM_10, 0);
gpio_set_direction(GPIO_ASIC_ENABLE, GPIO_MODE_OUTPUT);
gpio_set_level(GPIO_ASIC_ENABLE, 0);
break;
case DEVICE_GAMMA:
default:
Expand Down Expand Up @@ -528,7 +527,7 @@ void vButtonTimerCallback(TimerHandle_t xTimer) {

// Interrupt handler for BUTTON_BOOT
void IRAM_ATTR button_boot_isr_handler(void* arg) {
if (gpio_get_level(BUTTON_BOOT) == 0) {
if (gpio_get_level(GPIO_BUTTON_BOOT) == 0) {
// Button pressed, start the timer
if (!button_pressed) {
button_pressed = true;
Expand All @@ -551,7 +550,7 @@ static void configure_button_boot_interrupt(void) {
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_ANYEDGE, // Interrupt on both edges
.mode = GPIO_MODE_INPUT, // Set as input mode
.pin_bit_mask = (1ULL << BUTTON_BOOT), // Bit mask of the pin to configure
.pin_bit_mask = (1ULL << GPIO_BUTTON_BOOT), // Bit mask of the pin to configure
.pull_down_en = GPIO_PULLDOWN_DISABLE, // Disable pull-down mode
.pull_up_en = GPIO_PULLUP_ENABLE, // Enable pull-up mode
};
Expand All @@ -561,7 +560,7 @@ static void configure_button_boot_interrupt(void) {
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);

// Attach the interrupt handler
gpio_isr_handler_add(BUTTON_BOOT, button_boot_isr_handler, NULL);
gpio_isr_handler_add(GPIO_BUTTON_BOOT, button_boot_isr_handler, NULL);

ESP_LOGI(TAG, "BUTTON_BOOT interrupt configured");
}
Loading
Loading