Improve struct Videomode
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Thu, 1 Sep 2016 12:24:26 +0000 (15:24 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Mon, 26 Sep 2016 05:59:03 +0000 (08:59 +0300)
Enable set/get for sync polarities and interlace. Add
videomode_from_timings() helper to construct Videomode from non-X
timings.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
kms++/inc/kms++/videomode.h
kms++/src/videomode.cpp

index ec16969e41d9641ae90118d522da1c7a28d1c5af..39e56395c91193c1043ab6c4062a38f13b38d9ae 100644 (file)
@@ -9,6 +9,13 @@
 namespace kms
 {
 
+enum class SyncPolarity
+{
+       Undefined,
+       Positive,
+       Negative,
+};
+
 struct Videomode
 {
        std::string name;
@@ -32,8 +39,18 @@ struct Videomode
        uint16_t vsw() const { return vsync_end - vsync_start; }
        uint16_t vbp() const { return vtotal - vsync_end; }
 
-       bool interlace() const;
        float calculated_vrefresh() const;
+
+       bool interlace() const;
+       SyncPolarity hsync() const;
+       SyncPolarity vsync() const;
+
+       void set_interlace(bool ilace);
+       void set_hsync(SyncPolarity pol);
+       void set_vsync(SyncPolarity pol);
 };
 
+struct Videomode videomode_from_timings(uint32_t clock_khz,
+                                       uint16_t hact, uint16_t hfp, uint16_t hsw, uint16_t hbp,
+                                       uint16_t vact, uint16_t vfp, uint16_t vsw, uint16_t vbp);
 }
index 16330bb700dfb5e2c484b79d4dc5d9d2d82dba40..107ee3bff9ceadba5707522c2a03adfdeb02c819 100644 (file)
@@ -16,14 +16,92 @@ unique_ptr<Blob> Videomode::to_blob(Card& card) const
        return unique_ptr<Blob>(new Blob(card, &drm_mode, sizeof(drm_mode)));
 }
 
+float Videomode::calculated_vrefresh() const
+{
+       return (clock * 1000.0) / (htotal * vtotal) * (interlace() ? 2 : 1);
+}
+
 bool Videomode::interlace() const
 {
        return flags & DRM_MODE_FLAG_INTERLACE;
 }
 
-float Videomode::calculated_vrefresh() const
+SyncPolarity Videomode::hsync() const
 {
-       return (clock * 1000.0) / (htotal * vtotal) * (interlace() ? 2 : 1);
+       if (flags & DRM_MODE_FLAG_PHSYNC)
+               return SyncPolarity::Positive;
+       if (flags & DRM_MODE_FLAG_NHSYNC)
+               return SyncPolarity::Negative;
+       return SyncPolarity::Undefined;
+}
+
+SyncPolarity Videomode::vsync() const
+{
+       if (flags & DRM_MODE_FLAG_PVSYNC)
+               return SyncPolarity::Positive;
+       if (flags & DRM_MODE_FLAG_NVSYNC)
+               return SyncPolarity::Negative;
+       return SyncPolarity::Undefined;
+}
+
+void Videomode::set_interlace(bool ilace)
+{
+       if (ilace)
+               flags |= DRM_MODE_FLAG_INTERLACE;
+       else
+               flags &= ~DRM_MODE_FLAG_INTERLACE;
+}
+
+void Videomode::set_hsync(SyncPolarity pol)
+{
+       flags &= ~(DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC);
+
+       switch (pol) {
+       case SyncPolarity::Positive:
+               flags |= DRM_MODE_FLAG_PHSYNC;
+               break;
+       case SyncPolarity::Negative:
+               flags |= DRM_MODE_FLAG_NHSYNC;
+               break;
+       default:
+               break;
+       }
+}
+
+void Videomode::set_vsync(SyncPolarity pol)
+{
+       flags &= ~(DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC);
+
+       switch (pol) {
+       case SyncPolarity::Positive:
+               flags |= DRM_MODE_FLAG_PVSYNC;
+               break;
+       case SyncPolarity::Negative:
+               flags |= DRM_MODE_FLAG_NVSYNC;
+               break;
+       default:
+               break;
+       }
+}
+
+Videomode videomode_from_timings(uint32_t clock_khz,
+                                uint16_t hact, uint16_t hfp, uint16_t hsw, uint16_t hbp,
+                                uint16_t vact, uint16_t vfp, uint16_t vsw, uint16_t vbp)
+{
+       Videomode m { };
+       m.clock = clock_khz;
+
+       m.hdisplay = hact;
+       m.hsync_start = hact + hfp;
+       m.hsync_end = hact + hfp + hsw;
+       m.htotal = hact + hfp + hsw + hbp;
+
+       m.vdisplay = vact;
+       m.vsync_start = vact + vfp;
+       m.vsync_end = vact + vfp + vsw;
+       m.vtotal = vact + vfp + vsw + vbp;
+
+       return m;
 }
 
 }