FlexBook / Mbed 2 deprecated FlexBook171204a

Dependencies:   SDFileSystem app epson mbed msp430 pl tests

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vcom.cpp Source File

vcom.cpp

00001 /*
00002   Plastic Logic EPD project on MSP430
00003 
00004   Copyright (C) 2013 Plastic Logic Limited
00005 
00006   This program is free software: you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation, either version 3 of the License, or
00009   (at your option) any later version.
00010 
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014   GNU General Public License for more details.
00015 
00016   You should have received a copy of the GNU General Public License
00017   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 /*
00020  * vcom.c -- VCOM Calculation support
00021  *
00022  * Authors: Nick Terry <nick.terry@plasticlogic.com>
00023  *
00024  */
00025 
00026 #include "assert.h"
00027 #include "vcom.h"
00028 #include <stdlib.h>
00029 
00030 #define LOG_TAG "vcom"
00031 #include "utils.h"
00032 
00033 void vcom_init(struct vcom_cal *v, const struct pl_hw_vcom_info *c)
00034 {
00035     assert(v != NULL);
00036     assert(c != NULL);
00037 
00038     v->dac_dx = c->dac_x2 - c->dac_x1;
00039     v->dac_dy = c->dac_y2 - c->dac_y1;
00040     v->dac_offset = c->dac_y1 -
00041         DIV_ROUND_CLOSEST((c->dac_x1 * v->dac_dy),  v->dac_dx);
00042     v->swing = c->vgpos_mv - c->vgneg_mv;
00043     v->swing_ideal = c->swing_ideal;
00044     v->dac_step_mv = DIV_ROUND_CLOSEST(v->dac_dy, v->dac_dx);
00045 }
00046 
00047 int vcom_calculate(const struct vcom_cal *v, int input_mv)
00048 {
00049     int32_t scaled_mv;
00050     int dac_value;
00051 
00052     assert(v != NULL);
00053 
00054     scaled_mv = DIV_ROUND_CLOSEST(input_mv * v->swing, v->swing_ideal);
00055     dac_value = DIV_ROUND_CLOSEST((scaled_mv - v->dac_offset) * v->dac_dx,
00056                       v->dac_dy);
00057 
00058     LOG("input: %d, scaled: %ld, DAC reg: 0x%02X",
00059         input_mv, scaled_mv, dac_value);
00060 
00061     return dac_value;
00062 }