Created
September 9, 2012 01:08
-
-
Save stianeikeland/3681791 to your computer and use it in GitHub Desktop.
Pioneer SR-link control - Raspberry PI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <sys/mman.h> | |
#include <errno.h> | |
#include <stdint.h> | |
// SR Control pulses (IR pulses without modulation) | |
#define HDR_MARK 9000 | |
#define HDR_PAUSE 4500 | |
#define BIT_MARK 560 | |
#define ONE_PAUSE 1600 | |
#define ZERO_PAUSE 560 | |
// SR Control codes: | |
#define SR_VOLUME_UP 0xA55A50AF | |
#define SR_VOLUME_DOWN 0xA55AD02F | |
#define SR_TOGGLE_PWR 0xA55A38C7 | |
#define SR_INPUT_HDMI 0xA55A7A85 | |
static volatile uint32_t *gpio; | |
void sendCode(unsigned long data, int nbits); | |
void sendPulse(long microsecs); | |
int main(int argc, char **argv) | |
{ | |
int fd, i; | |
// Open memory handle | |
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC) ) < 0) { | |
printf("Unable to open /dev/mem: %s\n", strerror(errno)); | |
return -1; | |
} | |
// map memory to gpio at offset 0x20200000 (gpio start..) | |
gpio = (uint32_t *)mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x20200000); | |
if ((int32_t)gpio < 0){ | |
printf("Mmap failed: %s\n", strerror(errno)); | |
return -1; | |
} | |
//set gpio17 as an output | |
*(gpio + 1) = (*(gpio + 1) & ~(7 << 21)) | (1 << 21); | |
//set gpio17 high: | |
*(gpio + 7) = 1 << 17; | |
sleep(1); | |
for (i = 0; i < 5; i++) { | |
sendCode(SR_VOLUME_UP, 32); | |
sleep(1); | |
sendCode(SR_VOLUME_DOWN, 32); | |
sleep(1); | |
} | |
} | |
void sendPulse(long microsecs) | |
{ | |
// Take GPIO 17 low, wait, then high. (one pulse..) | |
*(gpio + 10) = 1 << 17; | |
usleep(microsecs); | |
*(gpio + 7) = 1 << 17; | |
} | |
void sendCode(unsigned long data, int nbits) | |
{ | |
int i; | |
sendPulse(HDR_MARK); | |
usleep(HDR_PAUSE); | |
for (i = 0; i < nbits; i++) | |
{ | |
sendPulse(BIT_MARK); | |
if (data & 0x80000000) | |
usleep(ONE_PAUSE); | |
else | |
usleep(ZERO_PAUSE); | |
data <<= 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SR is a common bus, and so every command is broadcast to every device daisy-chained together. A5 is the device type identifier for receivers. (A1 is tape decks, A2 is CD players, etc.) The format of a simple SR command is [frame header][device type ID][bitwise negation of device type ID][command code][bitwise negation of command code][stop bit].
So, yes, all commands intended for your receiver will start with A55A (5A being the happy-accident bitwise negation of A5). But all commands intended for your CD player will start with A25D (5D being the bitwise negation of A2).
And yes, many of the command codes were published by Pioneer. But they’re also just the exact same command codes sent by the device’s infrared remote, which have been extensively cataloged.