Root/tools/lib/atspi.c

Source at commit e2b2df2e315c6b0338aed53dffd1dce9cae8196e created 9 years 13 days ago.
By Werner Almesberger, Made the libatspi API driver-agnostic.
1/*
2 * lib/atspi.c - ATSPI access functions library
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdlib.h>
15#include <stdio.h>
16
17#include "driver.h"
18#include "atspi.h"
19
20
21extern struct atspi_driver atusb_driver;
22
23
24struct atspi_dsc {
25    struct atspi_driver *driver;
26    void *handle;
27};
28
29
30struct atspi_dsc *atspi_open(void)
31{
32    struct atspi_dsc *dsc;
33    struct atspi_driver *driver;
34    void *handle;
35
36    driver = &atusb_driver;
37    handle = driver->open();
38    if (!handle)
39        return NULL;
40    dsc = malloc(sizeof(*dsc));
41    if (!dsc) {
42        perror("malloc");
43        exit(1);
44    }
45    dsc->driver = driver;
46    dsc->handle = handle;
47    return dsc;
48}
49
50
51void atspi_close(struct atspi_dsc *dsc)
52{
53    if (dsc->driver->close)
54        dsc->driver->close(dsc->handle);
55    free(dsc);
56}
57
58
59void atspi_reset(struct atspi_dsc *dsc)
60{
61    if (dsc->driver->reset)
62        dsc->driver->reset(dsc->handle);
63}
64
65
66void atspi_reset_rf(struct atspi_dsc *dsc)
67{
68    dsc->driver->reset_rf(dsc->handle);
69}
70
71
72void atspi_reg_write(struct atspi_dsc *dsc, uint8_t reg, uint8_t value)
73{
74    dsc->driver->reg_write(dsc->handle, reg, value);
75}
76
77
78uint8_t atspi_reg_read(struct atspi_dsc *dsc, uint8_t reg)
79{
80    return dsc->driver->reg_read(dsc->handle, reg);
81}
82
83
84void atspi_buf_write(struct atspi_dsc *dsc, const void *buf, int size)
85{
86    dsc->driver->buf_write(dsc->handle, buf, size);
87}
88
89
90int atspi_buf_read(struct atspi_dsc *dsc, void *buf, int size)
91{
92    return dsc->driver->buf_read(dsc->handle, buf, size);
93}
94

Archive Download this file



interactive