ghnotgood commented on PR #3477:
URL: https://github.com/apache/nuttx-apps/pull/3477#issuecomment-4487331584
@acassis
> @ghnotgood ahh Ok, understood, probably you mean DAC instead of ADC!
Yes, DAC, sorry.
> So, did you implement a kernel driver to control this speaker over DAC and
timers? It should be nice to very it integrated into mainline to be used as
reference.
Not really. It is hacked solution, and I am not sure yet how it should look.
For now, it is like:
```
#define DAC_DEV "/dev/dac0"
#define SOUND_PIT_DEV "/dev/pit0"
#define DURATION_PIT_DEV "/dev/pit1"
/* A message to DAC defines loudness. */
struct dac_msg_s const dac_msg[2] = {
{
.am_channel = 0,
.am_data = 0x32, /* Loudness */
},
{
.am_channel = 0,
.am_data = 0x00,
},
};
/* Handle sound's frequency and sound's duration -- when to stop. */
void
handle_signal(int sn)
{
int r;
static int i = -1;
if (SIGUSR1 == sn) {
i += 1;
i %= 2;
r = write(dac_fd, &dac_msg[i], sizeof(*dac_msg));
if (sizeof(*dac_msg) != r) {
_err("ERROR: Write to %s failed: %s",
DAC_DEV, strerror(errno));
}
r = ioctl(sound_fd, OSIOC_START,
(unsigned long)((uintptr_t)&sound_info));
if (0 < r) {
_err("ERROR: %s ioctl failed: %s",
SOUND_PIT_DEV, strerror(errno));
}
} else if (SIGUSR2 == sn) {
r = ioctl(sound_fd, OSIOC_CANCEL,
(unsigned long)((uintptr_t)&drop_ts));
if (0 < r) {
_err("ERROR: %s ioctl failed: %s",
SOUND_PIT_DEV, strerror(errno));
}
playing = false;
}
}
static void
make_sound(struct rtttl_tone tone)
{
int r;
playing = true;
if (0 != tone.frequency_100hz) {
sound_info.ts.tv_sec = tone.period_us / 1000000;
sound_info.ts.tv_nsec = tone.period_us * 1000;
r = ioctl(sound_fd, OSIOC_START,
(unsigned long)((uintptr_t)&sound_info));
if (0 < r) {
_err("ERROR: %s ioctl failed: %s",
SOUND_PIT_DEV, strerror(errno));
}
}
duration_info.ts.tv_sec = tone.duration_us / 1000000;
duration_info.ts.tv_nsec = tone.duration_us * 1000;
r = ioctl(duration_fd, OSIOC_START,
(unsigned long)((uintptr_t)&duration_info));
if (0 < r) {
_err("ERROR: %s ioctl failed: %s",
DURATION_PIT_DEV, strerror(errno));
}
while (playing) ;
}
```
I am very happy to contribute meaningful code, but this is not a one, in my
opinion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]