-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scarlett2-ioctls.c
74 lines (56 loc) · 1.92 KB
/
scarlett2-ioctls.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-FileCopyrightText: 2023 Geoffrey D. Bennett <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
#include <stdio.h>
#include <alsa/asoundlib.h>
#include "scarlett2.h"
#include "scarlett2-ioctls.h"
int scarlett2_open_card(char *alsa_name, snd_hwdep_t **hwdep) {
return snd_hwdep_open(hwdep, alsa_name, SND_HWDEP_OPEN_DUPLEX);
}
int scarlett2_get_protocol_version(snd_hwdep_t *hwdep) {
int version = 0;
int err = snd_hwdep_ioctl(hwdep, SCARLETT2_IOCTL_PVERSION, &version);
if (err < 0)
return err;
return version;
}
int scarlett2_close(snd_hwdep_t *hwdep) {
return snd_hwdep_close(hwdep);
}
int scarlett2_reboot(snd_hwdep_t *hwdep) {
return snd_hwdep_ioctl(hwdep, SCARLETT2_IOCTL_REBOOT, 0);
}
static int scarlett2_select_flash_segment(snd_hwdep_t *hwdep, int segment) {
return snd_hwdep_ioctl(hwdep, SCARLETT2_IOCTL_SELECT_FLASH_SEGMENT, &segment);
}
static int scarlett2_erase_flash_segment(snd_hwdep_t *hwdep) {
return snd_hwdep_ioctl(hwdep, SCARLETT2_IOCTL_ERASE_FLASH_SEGMENT, 0);
}
int scarlett2_erase_config(snd_hwdep_t *hwdep) {
int err;
err = scarlett2_select_flash_segment(hwdep, SCARLETT2_SEGMENT_ID_SETTINGS);
if (err < 0)
return err;
return scarlett2_erase_flash_segment(hwdep);
}
int scarlett2_erase_firmware(snd_hwdep_t *hwdep) {
int err;
err = scarlett2_select_flash_segment(hwdep, SCARLETT2_SEGMENT_ID_FIRMWARE);
if (err < 0)
return err;
return scarlett2_erase_flash_segment(hwdep);
}
int scarlett2_get_erase_progress(snd_hwdep_t *hwdep) {
struct scarlett2_flash_segment_erase_progress progress;
int err = snd_hwdep_ioctl(
hwdep, SCARLETT2_IOCTL_GET_ERASE_PROGRESS, &progress
);
if (err < 0)
return err;
// translate progress from [1..num_blocks, 255] to [[0..100), 255]]
if (progress.num_blocks == 0 ||
progress.progress == 0 ||
progress.progress == 255)
return progress.progress;
return (progress.progress - 1) * 100 / progress.num_blocks;
}