Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Commit 407bbfa

Browse files
borneoatormodvolden
authored andcommitted
port: encapsulate get config string
this is last piece of serial port around the code. Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
1 parent b39c087 commit 407bbfa

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

main.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#define VERSION "0.3"
4242

4343
/* device globals */
44-
serial_t *serial = NULL;
4544
stm32_t *stm = NULL;
4645

4746
void *p_st = NULL;
@@ -145,9 +144,8 @@ int main(int argc, char* argv[]) {
145144
perror(port_opts.device);
146145
goto close;
147146
}
148-
serial = (serial_t *)port->private;
149147

150-
fprintf(diag, "Serial Config: %s\n", serial_get_setup_str(serial));
148+
fprintf(diag, "Interface %s: %s\n", port->name, port->get_cfg_str(port));
151149
if (init_flag && init_bl_entry(port, gpio_seq) == 0)
152150
goto close;
153151
stm = stm32_init(port, init_flag);

port.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ struct port_interface {
4545
port_err_t (*read)(struct port_interface *port, void *buf, size_t nbyte);
4646
port_err_t (*write)(struct port_interface *port, void *buf, size_t nbyte);
4747
port_err_t (*gpio)(struct port_interface *port, serial_gpio_t n, int level);
48+
const char *(*get_cfg_str)(struct port_interface *port);
4849
void *private;
4950
};
5051

serial_posix.c

+9
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ static port_err_t serial_posix_gpio(struct port_interface *port,
385385
return PORT_ERR_UNKNOWN;
386386
}
387387

388+
static const char *serial_posix_get_cfg_str(struct port_interface *port)
389+
{
390+
serial_t *h;
391+
392+
h = (serial_t *)port->private;
393+
return serial_get_setup_str(h);
394+
}
395+
388396
struct port_interface port_serial = {
389397
.name = "serial_posix",
390398
.flags = PORT_BYTE,
@@ -393,4 +401,5 @@ struct port_interface port_serial = {
393401
.read = serial_posix_read,
394402
.write = serial_posix_write,
395403
.gpio = serial_posix_gpio,
404+
.get_cfg_str = serial_posix_get_cfg_str,
396405
};

serial_w32.c

+9
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,14 @@ static port_err_t serial_w32_gpio(struct port_interface *port,
375375
return PORT_ERR_UNKNOWN;
376376
}
377377

378+
static const char *serial_w32_get_cfg_str(struct port_interface *port)
379+
{
380+
serial_t *h;
381+
382+
h = (serial_t *)port->private;
383+
return serial_get_setup_str(h);
384+
}
385+
378386
struct port_interface port_serial = {
379387
.name = "serial_w32",
380388
.flags = PORT_BYTE,
@@ -383,4 +391,5 @@ struct port_interface port_serial = {
383391
.read = serial_w32_read,
384392
.write = serial_w32_write,
385393
.gpio = serial_w32_gpio,
394+
.get_cfg_str = serial_w32_get_cfg_str,
386395
};

0 commit comments

Comments
 (0)