Skip to content

Commit 685afa8

Browse files
committed
eeptools: Add the POWER_SUPPLY atom
The POWER_SUPPLY atom describes the ability of the HAT to supply power to the Pi. This is declared in the EEPROM settings text file using the current_supply property. The default value for current_supply is zero, and unless a non-zero value is provided then the POWER_SUPPLY atom is omitted from the EEPROM image. Signed-off-by: Phil Elwell <[email protected]>
1 parent 660bba3 commit 685afa8

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

eeptools/eepdump.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
static struct var_blob_t dt_atom, custom_atom;
1010
static struct vendor_info_d vinf;
1111
static struct gpio_map_d gpiomap;
12+
static struct power_supply_d supply;
1213
static const char *blob_prefix;
1314

1415
static const char *atom_type_names[] ={
1516
[ATOM_INVALID_TYPE] = "invalid",
16-
[ATOM_VENDOR_TYPE] = "vendor type",
17+
[ATOM_VENDOR_TYPE] = "vendor",
1718
[ATOM_GPIO_TYPE] = "GPIO map",
1819
[ATOM_DT_TYPE] = "DT overlay",
1920
[ATOM_CUSTOM_TYPE] = "manufacturer custom data",
2021
[ATOM_GPIO_BANK1_TYPE] = "GPIO map bank 1",
22+
[ATOM_POWER_SUPPLY_TYPE] = "power supply",
2123
};
2224

2325
static void dump_data(FILE *out, const uint8_t *data, int len)
@@ -165,6 +167,14 @@ static int read_bin(const char *in, const char *outf)
165167
fprintf(out, "product \"%s\" # length=%u\n", vinf.pstr, vinf.pslen);
166168
break;
167169

170+
case ATOM_POWER_SUPPLY_TYPE:
171+
if (!eepio_atom_power_supply(&supply))
172+
goto atom_read_err;
173+
174+
fprintf(out, "# power supply\n");
175+
fprintf(out, "current_supply %u\n", supply.current_supply);
176+
break;
177+
168178
case ATOM_GPIO_BANK1_TYPE:
169179
bank1 = true;
170180
/* fall through... */

eeptools/eeplib.c

+6
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,12 @@ bool eepio_atom_vinf(struct vendor_info_d *vinf)
312312
return !eepio_got_error();
313313
}
314314

315+
bool eepio_atom_power_supply(struct power_supply_d *power)
316+
{
317+
eepio_blob(power, POWER_SUPPLY_SIZE);
318+
return !eepio_got_error();
319+
}
320+
315321
bool eepio_atom_gpio(struct gpio_map_d *map)
316322
{
317323
eepio_blob(map, GPIO_SIZE);

eeptools/eeplib.h

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define VENDOR_SIZE 22
1515
#define GPIO_SIZE 30
1616
#define GPIO_BANK1_SIZE 20
17+
#define POWER_SUPPLY_SIZE 4
1718
#define CRC_SIZE 2
1819

1920
#define GPIO_MIN 2
@@ -40,6 +41,7 @@ enum atom_type_t
4041
ATOM_DT_TYPE = 0x0003,
4142
ATOM_CUSTOM_TYPE = 0x0004,
4243
ATOM_GPIO_BANK1_TYPE = 0x0005,
44+
ATOM_POWER_SUPPLY_TYPE = 0x0006,
4345
ATOM_HINVALID_TYPE = 0xffff
4446
};
4547

@@ -102,6 +104,12 @@ struct gpio_map_d
102104
unsigned char pins[GPIO_COUNT];
103105
};
104106

107+
/* Power supply atom data */
108+
struct power_supply_d
109+
{
110+
uint32_t current_supply; /* In milliamps */
111+
};
112+
105113
extern struct header_t eep_header;
106114
extern struct atom_t eep_atom_header;
107115
extern uint16_t eep_atom_crc;
@@ -113,6 +121,7 @@ bool eepio_atom_start(enum atom_type_t *ptype, uint32_t *pdlen);
113121
bool eepio_atom_vinf(struct vendor_info_d *vinf);
114122
bool eepio_atom_gpio(struct gpio_map_d *map);
115123
bool eepio_atom_gpio_bank1(struct gpio_map_d *map);
124+
bool eepio_atom_power_supply(struct power_supply_d *power);
116125
bool eepio_atom_var(struct var_blob_t *var);
117126
void eepio_atom_end(void);
118127
void eepio_clear_error(void);

eeptools/eepmake.c

+39-4
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@
1313
#include "eeplib.h"
1414

1515
static struct vendor_info_d vinf;
16-
static struct gpio_map_d gpiomap_bank0, gpiomap_bank1;
1716
static struct var_blob_t dt_blob;
1817
struct var_blob_t *custom_blobs;
1918
static struct var_blob_t *data_blob;
2019
bool in_string;
2120

22-
static bool product_serial_set, product_id_set, product_ver_set, vendor_set, product_set,
23-
gpio_drive_set, gpio_slew_set, gpio_hysteresis_set, gpio_power_set,
21+
/* Common features */
22+
static bool product_serial_set, product_id_set, product_ver_set, vendor_set, product_set;
23+
static bool has_dt;
24+
25+
/* Legacy V1 features */
26+
static struct gpio_map_d gpiomap_bank0, gpiomap_bank1;
27+
static bool has_gpio_bank0, has_gpio_bank1;
28+
static bool gpio_drive_set, gpio_slew_set, gpio_hysteresis_set, gpio_power_set,
2429
bank1_gpio_drive_set, bank1_gpio_slew_set, bank1_gpio_hysteresis_set;
2530

26-
static bool has_dt, has_gpio_bank0, has_gpio_bank1;
31+
/* HAT+ features */
32+
static struct power_supply_d power_supply;
33+
static bool current_supply_set, has_power_supply;
2734

2835
static unsigned int custom_ct, data_cap, custom_cap;
2936

@@ -39,6 +46,14 @@ static void fatal_error(const char *msg, ...)
3946
exit(1);
4047
}
4148

49+
static void hatplus_required(const char *cmd)
50+
{
51+
if (hat_format >= EEP_VERSION_HATPLUS)
52+
return;
53+
printf("'%s' not supported on V1 HAT\n", cmd);
54+
exit(1);
55+
}
56+
4257
static void hatplus_unsupported(const char *cmd)
4358
{
4459
if (hat_format == EEP_VERSION_HATV1)
@@ -101,6 +116,14 @@ static int write_binary(const char *out)
101116
eepio_atom_end();
102117
}
103118

119+
if (has_power_supply)
120+
{
121+
type = ATOM_POWER_SUPPLY_TYPE;
122+
eepio_atom_start(&type, NULL);
123+
eepio_atom_power_supply(&power_supply);
124+
eepio_atom_end();
125+
}
126+
104127
eepio_end();
105128

106129
fclose(fp);
@@ -327,6 +350,18 @@ static int parse_command(char *cmd, char *c)
327350
vinf.pslen = strlen(vinf.pstr);
328351
}
329352

353+
/* HAT+ features */
354+
else if (strcmp(cmd, "current_supply") == 0)
355+
{
356+
hatplus_required(cmd);
357+
sscanf(c, "%100s %u", cmd, &power_supply.current_supply);
358+
if (power_supply.current_supply)
359+
{
360+
current_supply_set = true;
361+
has_power_supply = true;
362+
}
363+
}
364+
330365
/* GPIO map related part */
331366
else if (strcmp(cmd, "gpio_drive") == 0)
332367
{

eeptools/eeprom_settings.txt

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ vendor "ACME Technology Company"
2727
# ASCII product string (max 255 characters)
2828
product "Special Sensor Board"
2929

30+
# How much current the HAT+ can supply, in milliamps
31+
current_supply 0
32+
3033
# Which Device Tree overlay to load
3134
dt_blob "acme-sensor"
3235

0 commit comments

Comments
 (0)